in reply to Variables as a variable name... (I know you shouldn't but...)

Thank you broomduster, Bloodnok & Skeeve

Between your responses I have managed to create (an admittedly still messy and improvable) a solution to the 'problem' set.

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:

# your dataplot should then go like this: @data2plot = ( [ @results{qw/dayofweek canning multipack quest/} ] );
was really helpful for showing me how to package my data ready to feed into GD::Graph.

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...

#! 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!
If you've read through that you'll probably be wincing at a number of things:
a) Having gone to the effort to do everything in a Hash of Hashes (I think) I've then gone and manually created arrays from this b) I've only actually drawn a graph of one of the datasets c) How little you perceive I've learned and done from your collective postings.

All I can say is that now I have something that works I will try to improve it, in a variety of ways. I have actually spent much of my day (all the time I've been at my desk) working on this - so despite it's simple appearance, actually quite a chunk of time and effort has gone in and I intend to spend tomorrow on it too (certainly beats working).

So again... Thankyou all.
Staring at an Everest sized learning curve

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

    I guess you meant the inner while loop?

    while (my $data = $sth->fetchrow_hashref()) { # %$data is now a hash. # keys are the column's names # values are the column's values while (my($k, $v)= each %$data) { # Now I loop over each column-value pair push( @{$results{$k}}, $v ); # pushing into the results' hashes all the values. # So $result{'canning'} is a reference to an array # for all the canning-values etc.pp. } }

    s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
    +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e