2mths has asked for the wisdom of the Perl Monks concerning the following question:
The 'problem' I'm trying to solve (probably trivial, but not for me):
A database query returns results like:
DayOfWeek | ProductionLine | Output |
---|---|---|
2 | CANNING | 18353 |
2 | MULTIPACK | 14878 |
2 | QUEST | 911 |
3 | CANNING | 46775 |
3 | MULTIPACK | 42601 |
3 | QUEST | 1564 |
4 | CANNING | 81302 |
4 | MULTIPACK | 67542 |
4 | QUEST | 1879 |
These are presented to the rest of my script as $results[0], $results1 and $results2.
Ultimately I want to get this data into several arrays
@dayofweek, which would contain ('2', '3', '4')
@canning, which would contain ('18353', '46775' etc)
@multipack and @quest (I'm sure you get the picture).
Then I think I can do @data_to_plot = ( [@dayofweek], [@canning], [@multipack], [@quest] ); which I can happily feed into GD::Graph to get a pretty graph drawn for me.
I could achieve what I need to by doing three separate queries of the database and pushing results into a separate array each time. Or a lot of if, elsif, else pattern matching. Indeed the former is what I'm currently doing. However I'm sure there is a 'better' way.
A way, but I am led to understand a bad way, of achieving this would be to try and push the Output figure, $results2, for each line of results into an array which has as it's name the value of the Production Line, $results1. I think this is possible, though I haven't managed to work out the syntax (despite a good look through Chapter 9, Data Structures, of Programming Perl). However in searching online for an example of the syntax I came across a copy of a newsgroup post about why naming variables with other variables is a bad idea.
Thus I have journeyed to prostrate myself before the gates of the Monastery to ask for any drops of wisdom that a passing monk might care to pass my way.
2mths - Thoroughly depressed at his lack of understanding and seeming inability to rectify the situation.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Variables as a variable name... (I know you shouldn't but...)
by broomduster (Priest) on Aug 14, 2008 at 10:05 UTC | |
Re: Variables as a variable name... (I know you shouldn't but...)
by Skeeve (Parson) on Aug 14, 2008 at 11:56 UTC | |
Re: Variables as a variable name... (I know you shouldn't but...)
by Bloodnok (Vicar) on Aug 14, 2008 at 11:52 UTC | |
Re: Variables as a variable name... (I know you shouldn't but...)
by injunjoel (Priest) on Aug 14, 2008 at 23:03 UTC | |
by Skeeve (Parson) on Aug 15, 2008 at 05:54 UTC | |
Re: Variables as a variable name... (I know you shouldn't but...)
by 2mths (Beadle) on Aug 14, 2008 at 15:49 UTC | |
by Skeeve (Parson) on Aug 14, 2008 at 19:33 UTC |