#!/usr/bin/perl -w use strict; my $pid; &start_gnuplot; sub start_gnuplot{ $pid = open(GP, "| '/usr/bin/gnuplot' 2>&1 "); syswrite(GP, "plot sin(x)\n"); sleep 2; syswrite(GP, "plot tan(x)\n"); sleep 2; syswrite(GP, "quit\n"); } #### #!/usr/bin/perl use warnings; use strict; # echo "plot sin (x)" | gnuplot -persist use Tk; use Tk::LabEntry; use FileHandle; my $gnuplot_path = "/usr/bin/gnuplot"; my $top = new MainWindow; my $function = "sin(x)"; my $funcentry = $top->LabEntry( -label => 'Function:', -textvariable => \$function, -labelPack => [ -side => 'left' ] )->pack; my $butframe = $top->Frame->pack( -anchor => 'w' ); my $plotbutton = $butframe->Button( -text => 'Plot', -command => \&plot, )->pack( -side => 'left' ); $butframe->Button( -text => 'Quit', -command => \&quit, )->pack( -side => 'left' ); $top->protocol( 'WM_DELETE_WINDOW', \&quit ); my $gnuplot = new FileHandle( "| $gnuplot_path" ); $gnuplot->autoflush( 1 ); $top->bind( "", sub { $plotbutton->invoke } ); MainLoop; sub plot { $gnuplot->print( "plot $function\n" ) if $function ne ''; } sub quit { $gnuplot->close; $top->destroy; }