It is possible to calling gnuplot directly from perl script and plot the data that processed before in perl program. Just for example.. if I have this data:

{56, 57, 56, 55, 54, 53, 54, 56, 58, 59, 61, 52, 53, 54, 55, 56, 57, 55, 55, 54, 45, 46, 48, 49, 50, 51, 52, 53, 56, 57, 58, 59, 54, 53, 53, 45,46,47,48,49}

I want to calculate the confidence of interval and plotting it.. so my way to Rome is: “Process data using perl”->”save output as file”->”Plot data using Gnuplot (by reading output file)”. More or less It did my job.

my code to calculate average and standard deviation:

use List::Util qw(sum);
#the data
@data=(56,57,56,55,54,53,54,56,58,59,61,52,53,
54,55,56,57,55,55,54,45,46,48,49,50,51,
52,53,56,57,58,59,54,53,53,45,46,47,48,49);
#average
$avg=sum(@data)/@data;
#standard deviation
foreach $x (@data) {
$z+=($x-$avg)**2;
}
$std=sqrt($z/(scalar(@data)-1));

I use “sum” function that provided in “List::Util” module to reduce iteration. And then save the output as a file:

open (MYFILE, '>data.txt');
print MYFILE "#Times(n)    Sample(V)    Error\n";
$x=0;
foreach $y (@data) {
print MYFILE ++$x."\t".$y."\t".$std."\n";
}
close (MYFILE);

Perl support IO & File operation through “open” function. The last job is call Gnuplot to plot saved file before. Still using “open” function, I did it like this:

my $pid = open(GP, "| '/usr/bin/gnuplot' 2>&1 ");

and then give it some jobs to do like:

syswrite(GP, "reset\n");
syswrite(GP, "set grid\n");
syswrite(GP, "set title \"Graph of confidence interval\"\n");
syswrite(GP, "set xlabel \"Times (n)\"\n");
syswrite(GP, "set ylabel \"Output Sample (V)\"\n");
syswrite(GP, "plot [0:50][0:70] ".$avg." with lines lt 1 title \"Average\", \"data.txt\" title \"\" with yerrorbars,\"data.txt\" title \"\" with lines\n");

Full source code can be looked over here and this is my final gnuplot output.

some resource is not successfully recovered :(