use Chart::Gnuplot; use strict; use warnings; sub createDs { my ($dsX, $dsY, $name) = @_; my $dataSet = Chart::Gnuplot::DataSet->new( xdata => [@$dsX], ydata => [@$dsY], title => $name, style => "linespoints"); return $dataSet; } sub readDatasets { my $filename = shift; my $name = "unnamed"; my @result; my (@dataX, @dataY); open my $fh, '<', $filename; while (my $line = <$fh>) { if ($line =~ /^\*\*/) { if (@dataX) { push @result, createDs(\@dataX, \@dataY, $name); @dataX = (); @dataY = (); } next; } if ($line =~ /^\*/) { if ($line =~ /NAME=(.+)/) { $name = $1; } next; } if ($line =~ /(.+), (.+?)$/) { push @dataX, $1; push @dataY, $2; } } if (@dataX) { push @result, createDs(\@dataX, \@dataY, $name); } return @result; } # Create chart object and specify the properties of the chart my $chart = Chart::Gnuplot->new( output => "/tmp/koer.png", title => "Simple testing", xlabel => "My x-axis label", ylabel => "My y-axis label", ); my @ds = readDatasets("koer.dat"); # Plot the data set on the chart $chart->plot2d(@ds);