如何从perl调用gnuplot脚本

时间:2012-07-25 09:00:44

标签: perl gnuplot

我有一个gnu.gp文件:

# grphist.conf
set terminal canvas
#Terminal type set to 'canvas'
#Options are ' solid butt size 600,400 fsize 10 lw 1 fontscale 1 standalone'
set output 'output.html'  

set grid
set xtic rotate by 90
set style data histograms
set style fill solid 1.00 border -1
#$ cat grphist.conf | gnuplot
plot "c_time"  using 2:xtic(1) title "time to number of UIDs"

但是,我必须将它与perl脚本集成。

2 个答案:

答案 0 :(得分:9)

您可以打开gnuplot的管道:

use autodie qw(:all);
open my $GP, '|-', 'gnuplot';

print {$GP} <<'__GNUPLOT__';
    set xrange [-5:5];
    plot sin(x);
__GNUPLOT__

close $GP;

或者,您可以在CPAN上找到Chart::Gnuplot

答案 1 :(得分:2)

`gnuplot <your file>`; #linux
`wgnuplot.exe <your file>`; #win

system("gnuplot <your file>"); #linux
system("wgnuplot.exe <your file>"); #win

exec("gnuplot <yout file>"); #linux
exec("wgnuplot.exe <your file>"); #win

您的选择取决于:

What's the difference between Perl's backticks, system, and exec?