3

I have a gnu.gp file :

# 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"

But, I have to integrate this with a perl script.

choroba
  • 231,213
  • 25
  • 204
  • 289
user1551050
  • 31
  • 1
  • 2

2 Answers2

10

You can open a pipe to gnuplot:

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

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

close $GP;

Or, you can reach for Chart::Gnuplot on CPAN.

daxim
  • 39,270
  • 4
  • 65
  • 132
choroba
  • 231,213
  • 25
  • 204
  • 289
  • When I tride your code, I get an error `Can't find string terminator "__GNUPLOT__" anywhere before EOF at scripts/temp.pl`. Any thoughts? Thanks. – SSilk Nov 28 '16 at 21:40
  • @SSilk: Weird. I can see `__GNUPLOT__` on line 7 clearly. – choroba Nov 28 '16 at 21:42
  • Thanks for the quick response! I igured it out. I had taken your code snippet and put it in a code block that was indented. It doesn't like the `__GNUPLOT__` on Line 7 being indented. I should have noticed that when that's indented, the syntax highlighting after it breaks. – SSilk Nov 28 '16 at 21:50
  • @SSilk: Exactly. We might get indented here docs in the coming Perl 5 version, though. – choroba Nov 28 '16 at 22:07
  • Thanks. I have another question. When I run your code right now, the results of gnuplot print on screen (I'm using `term dumb`). Can I instead capture them in a variable, e.g. `my $temp` for printing later? I can't figure it out, but I'm pretty new to this piping syntax. – SSilk Nov 29 '16 at 14:54
  • @SSilk: Usually, you'd set prompt to `png` or `pdfcairo` or whatever, and `set output "filename"`. – choroba Nov 29 '16 at 15:45
2
`gnuplot <your file>`; #linux
`wgnuplot.exe <your file>`; #win

or

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

or

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

what you choose depends on:

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

Community
  • 1
  • 1
René Kolařík
  • 1,244
  • 1
  • 10
  • 18