in reply to save a png image
As someone else pointed out, you should check for errors. Not only with $graph->plot but also with open, binmode, print and close. These all return undef on failure and have the error in $!.
open TMPFILE, ">file.png" or die $!; binmode TMPFILE or die $!; print TMPFILE $db_image->png or die $!; close TMPFILE or die $!;
This is the bare minimum of error checking and reporting that you should do. It is perhaps a good idea to make full sentences: "Could not open file.png: $!\n".
Alternatively, you can use the Fatal module to wrape open, binmode and close:
Note that I used a lexical filehandle here. Globals are bad for many reasons. See Coping with scoping for information about that.use Fatal qw(open binmode close); open my $tmpfile, ">file.png"; binmode $tmpfile; print $tmpfile $db_image->png or die $!; close $tmpfile;
When you have done all this, it's time to take indentation lessons :) In fact, you should probably just get a good Perl book or tutorial to learn from. (Like Beginning Perl or this tutorial or one of the many non-free resources out there.)
Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: save a png image
by Anonymous Monk on Mar 09, 2004 at 17:20 UTC |