I am doing something improperly with references, but I can't see it! This is the error I get.

Can't call method "gif" on an undefined value at test2.pl line 80.
That line is 3rd from the bottom on the snippet below.
this is the piece of code that generates the above error:
my $data = GD::Graph::Data->new(); my $graph = GD::Graph::bars->new(); my $format = $graph->export_format; if ( $dbh = DBI->connect("DBI:ODBC:$INI{DSN}",$INI{DBuser},$INI{DBp +ass}) ) { my $gotdata = 0; my $stmt = 'SELECT SysID FROM MeterEvent WHERE Sysid >= 2 and Sy +sid < = 10'; if ( my $sth = $dbh->prepare($stmt) ) { if ( my $rows = $sth->execute ) { while (my @row = $sth->fetchrow_array) { $data->add_point(@row); $gotdata = 1; } } } $dbh->disconnect(); } else { print "Database Error$br\n"; } my $gd = $graph->plot($data); open(IMG, '>file.gif') or die $!; binmode IMG; print IMG $gd->gif; # this is the line # 80 if ( defined $gd ) { print " 4.gd defined\n"; } else {print " 4.gd +NOT defined\n"; } close IMG;
The GD::Graph::Data manual states the following in the examples section
use GD::Graph::Data; use GD::Graph::bars; my $data = GD::Graph::Data->new(); $data->read(file => '/data/sales.dat', delimiter => ','); $data = $data->copy(wanted => [2, 4, 5]); # Add the newer figures from the database use DBI; # do DBI things, like connecting to the database, statement # preparation and execution while (@row = $sth->fetchrow_array) { $data->add_point(@row); } my $chart = GD::Graph::bars->new(); my $gd = $chart->plot($data);
Thanks for your help!

In reply to Problems with references using GD::Graph::Data by gary kuipers

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.