#Sept 10, 2017 by tech @ltimas #Perl Script to create a GNUplot Chart using existing data in tab deliminted text file. use strict; use warnings; my (@time, @gold, @silver, @auag, @array); my $index=0; open (FH,"GoldSilverPrices.txt") or die "Cannot open file"; while (){ @array=split/\s/,$_; $time[$index]=$array[0]; $gold[$index]=$array[1]; $silver[$index]=$array[2]; $auag[$index]=$array[1]/$array[2]; $index=$index + 1; } close FH or die "Cannot close file handle"; open FH,">GLDSLVratio" or die "Cannot open data file"; for (my $i=0; $i <= $index -1; $i++) { my $line = join("\t",$time[$i],$gold[$i],$silver[$i],$auag[$i]); print FH $line . "\n"; } close FH or die "Cannot read to data file"; open my $PROGRAM, '|-', 'gnuplot' or die "Couldn't pipe to gnuplot: $!"; #Print out the Gold Chart say {$PROGRAM} "set title 'Price of Gold averaged yearly'"; say {$PROGRAM} 'set xrange [1975:2020]'; say {$PROGRAM} 'set yrange [0.000:2000]'; say {$PROGRAM} 'set y2range [0.000:2000]'; say {$PROGRAM} 'set xtic 5'; say {$PROGRAM} 'set ytic 250'; say {$PROGRAM} 'set y2tic 250'; say {$PROGRAM} 'set pointsize 1.5'; say {$PROGRAM} "set xlabel 'YEAR'"; say {$PROGRAM} "set ylabel 'USD per Ounce Troy'"; say {$PROGRAM} 'set key left box'; say {$PROGRAM} 'set terminal postscript eps enhanced'; say {$PROGRAM} "set output 'Gold2017.eps'"; say {$PROGRAM} "plot 'GLDSLVratio' using 1:2 title 'Gold' with linespoints pt 5"; #Print out the Silver Chart say {$PROGRAM} "set title 'Price of Silver averaged yearly'"; say {$PROGRAM} 'set xrange [1975:2020]'; say {$PROGRAM} 'set yrange [0.000:50]'; say {$PROGRAM} 'set y2range [0.000:50]'; say {$PROGRAM} 'set xtic 5'; say {$PROGRAM} 'set ytic 5'; say {$PROGRAM} 'set y2tic 5'; say {$PROGRAM} 'set pointsize 1.5'; say {$PROGRAM} "set xlabel 'YEAR'"; say {$PROGRAM} "set ylabel 'USD per Ounce Troy'"; say {$PROGRAM} 'set key left box'; say {$PROGRAM} 'set terminal postscript eps enhanced'; say {$PROGRAM} "set output 'Silver2017.eps'"; say {$PROGRAM} "plot 'GLDSLVratio' using 1:3 title 'Silver' with linespoints pt 6"; #Print out the Ratio of Au to Ag say {$PROGRAM} "set title 'Ratio Au to Ag averaged yearly'"; say {$PROGRAM} 'set xrange [1975:2020]'; say {$PROGRAM} 'set yrange [0.000:100]'; say {$PROGRAM} 'set y2range [0.000:100]'; say {$PROGRAM} 'set xtic 5'; say {$PROGRAM} 'set ytic 10'; say {$PROGRAM} 'set y2tic 10'; say {$PROGRAM} 'set pointsize 1.5'; say {$PROGRAM} "set xlabel 'YEAR'"; say {$PROGRAM} "set ylabel 'Au-Ag'"; say {$PROGRAM} 'set key left box'; say {$PROGRAM} 'set terminal postscript eps enhanced'; say {$PROGRAM} "set output 'Ratio2017.eps'"; say {$PROGRAM} "plot 'GLDSLVratio' using 1:4 title 'Au-Ag' with linespoints pt 7"; close $PROGRAM;