in reply to Variables as a variable name... (I know you shouldn't but...)
broomduster - I found the explanation and words that accompanies your snippet as helpful as the snippet itself. I still have no idea how my($day, $line, $output) = (split); works, I haven't managed to emulate it in my code, but by being bit more long winded I was able to emulate the next line and learn how I might populate a Hash of Hashes. (I have started reading through the first link you posted and will get onto the second.)
Skeeve - Short and sweet. I'm afraid to say that even in that short snippet you lost me in the while loop but this:
was really helpful for showing me how to package my data ready to feed into GD::Graph.# your dataplot should then go like this: @data2plot = ( [ @results{qw/dayofweek canning multipack quest/} ] );
Bloodnok - I'm afraid most of your example code went a long way over my head. Still knowing what it does and what the output looks like I'm hoping I can still make use of it to more eloquently solve my 'problem' (the same can be said for the code of the others that I don't yet understand.)
It seems only reasonable to post (for ridicule if nothing else) my code. So abbreviating the bits that don't really matter...
If you've read through that you'll probably be wincing at a number of things:#! c:/perl/bin/perl.exe -w use GD::Graph::bars; #having connected to the database and composed a query, $query my %outputs; $db->Sql("$query"); while ($db->FetchRow()) { @results = $db->Data ; $day = $results[0] ; $line = $results[1] ; $output = $results[2] ; $outputs{$line}{$day} = $output; } # create individual arrays of data foreach $key (keys %outputs) { foreach $key2 (sort keys %{ $outputs{$key}}) { print "key: $key \t key2: $key2 \t data: $outputs{$key}{$key2} + \n"; push( @{$key}, $outputs{$key}{$key2}); $repeateddays{$key2}=$key2; } } # a hash with my days in (not very clever but neither am I) @days = (sort keys %repeateddays); # A visual check things have worked print "At canning = @CANNING \t quest = @QUEST \t MULTIPACK = @MULTIPA +CK \t days = @days\n"; # Put the data into a format GD::Graph likes @datatoplot = ( [@days], [@CANNING] ); # Set up and draw my graph my $mygraph3 = GD::Graph::bars->new(400, 250); $mygraph3->set( # some stuff ) or warn $mygraph3->error; my $myimage = $mygraph->plot(\@datatoplot) or die $mygraph3->error; $filename = "multi_layer_hash_development.png"; open (PRODGRAPHCUMU, ">c:/perl/bin/Durge/GD/" . $filename) ; # Make sure we are writing to a binary stream binmode PRODGRAPHCUMU; print PRODGRAPHCUMU $myimage->png; exit 0; # Voila I have a pretty graph!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Variables as a variable name... (I know you shouldn't but...)
by Skeeve (Parson) on Aug 14, 2008 at 19:33 UTC |