in reply to Problem passing GD image object

Your immediate problem is that the line:

$graphimage = $graph->plot(\@data) or die $graph->error;

in sub plot replaces the object you passed in. The easiest way to handle the issue is to simply return the object from plot. You don't need to pass anything in:

my $g = plot (); ... sub plot { my @data = ( ... ) or die $graph->error; return $graph->plot(\@data) or die $graph->error; }

DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re^2: Problem passing GD image object
by cormanaz (Deacon) on Mar 18, 2007 at 00:45 UTC
    You're right, that fixed it. Thanks.

    I still don't understand, tho. Even if I replaced the object, it seems like the replaced object should have worked anyway.

      You would need to pass a reference to the object then update the referenced value:

      plot (\$g); ... $$graphimage = $graph->plot(\@data) or die $graph->error;

      DWIM is Perl's answer to Gödel