K
kj
I need to generate and view a large number of data plots. My plan
for this was to have a loop that at each iteration would generate
the plot, display it, and wait for keyboard input before proceeding
to the next iteration. (FWIW, this code is to run on a remote
Linux system, and the display should take place on a local Mac OS
X workstation running an X11 server.)
The code I've written succeeds in displaying the graph, but somehow
the displaying of the graph the script's execution, so the script
does not get to request for keyboard input to move on to the next
iteration.
The relevant portion of the code is shown below. (In this snippet
I have omitted all error checking and other such details for clarity;
still, I confirmed that this simplified version of the code displays
the behavior I described above.) The place where the problem occurs
is indicated with "###".
# unbuffer selected output handle (STDOUT)
$| = 1;
for my $data ( @data ) {
my $chart = GD::Graph::lines->new( 400, 300 );
$chart->set( transparent => 0 );
# next line produces a GD::Image object
my $gd = $chart->plot( $data );
open my $IMG, '|-', 'display';
print $IMG $gd->png;
# display won't happen without this line!
close $IMG;
### script stalls before executing the next line
print "Press any key to continue... ";
ReadMode 'cbreak';
ReadKey( 0 );
ReadMode 'normal';
print "\n";
}
If someone could explain to me why this snippet is not behaving as
I expect it to I'd be most thankful.
BTW, I found it surprising that I needed to close the $IMG handle
for the display to appear; turning on autoflush on the handle was
not enough.
Maybe the problem with the code above has more to do with a
peculiarity of the 'display' command (from the ImageMagick suite)
than with the Perl code? If so, is there a better way to achieve
what I trying to do?
Any suggestions or comments would be much appreciated.
TIA!
kj
for this was to have a loop that at each iteration would generate
the plot, display it, and wait for keyboard input before proceeding
to the next iteration. (FWIW, this code is to run on a remote
Linux system, and the display should take place on a local Mac OS
X workstation running an X11 server.)
The code I've written succeeds in displaying the graph, but somehow
the displaying of the graph the script's execution, so the script
does not get to request for keyboard input to move on to the next
iteration.
The relevant portion of the code is shown below. (In this snippet
I have omitted all error checking and other such details for clarity;
still, I confirmed that this simplified version of the code displays
the behavior I described above.) The place where the problem occurs
is indicated with "###".
# unbuffer selected output handle (STDOUT)
$| = 1;
for my $data ( @data ) {
my $chart = GD::Graph::lines->new( 400, 300 );
$chart->set( transparent => 0 );
# next line produces a GD::Image object
my $gd = $chart->plot( $data );
open my $IMG, '|-', 'display';
print $IMG $gd->png;
# display won't happen without this line!
close $IMG;
### script stalls before executing the next line
print "Press any key to continue... ";
ReadMode 'cbreak';
ReadKey( 0 );
ReadMode 'normal';
print "\n";
}
If someone could explain to me why this snippet is not behaving as
I expect it to I'd be most thankful.
BTW, I found it surprising that I needed to close the $IMG handle
for the display to appear; turning on autoflush on the handle was
not enough.
Maybe the problem with the code above has more to do with a
peculiarity of the 'display' command (from the ImageMagick suite)
than with the Perl code? If so, is there a better way to achieve
what I trying to do?
Any suggestions or comments would be much appreciated.
TIA!
kj