GD::Graph problem -> Fixed

Mike Starke plug-discuss@lists.plug.phoenix.az.us
Thu, 27 Mar 2003 14:52:26 -0500


On Thu, Mar 27, 2003 at 01:25:25PM -0500, Mike Starke wrote:
/_In trying to generate a graph using GD::Graph
/_I keep getting the error:
/_Argument "AL AFC" isn't numeric in addition (+) at /usr/share/perl5/GD/Graph/pie.pm line 232.
/_
/_I think this is a quoting issue, and here is why:
/_Below is the loop I use the create my array that
/_is used in the plot (@data). The loop works,
/_but GD's plot chokes on the data (error msg above).
/_
/_while (my @ary = $sth->fetchrow_array()) {
/_  push (@data, [@ary]);
/_}
/_
/_Below is a handcrafted array using the first three rows
/_returned from my sql statement. This works.
/_#
/_#my @data = (['AL ADHC','AL AFC','AL CENTER-DI'],[30,12,119]);
/_
/_I guess my question can be distilled down to this:
/_How can I create an array from a two column sql query
/_which has the 'format' as the one I handcrafted above?
/_
/_Below is my line which creates thew graph.
/_print IMG $graph->plot(\@data)->png;
/_

I fixed my own problem. However, I do not understand why it works.
What makes these two differant? (I know some of you Perl guys are shaking
your heads on this one, but how else am I to learn? :-)

#while (@ary = $sth->fetchrow_array()) {
#  push (@data, [@ary]);
#}

while (($c1, $c2) = $sth->fetchrow_array()) {
  push (@{$data[0]}, $c1);
  push (@{$data[1]}, $c2);
}