The 'problem' I'm trying to solve (probably trivial, but not for me):

A database query returns results like:
DayOfWeekProductionLineOutput
2 CANNING 18353
2 MULTIPACK 14878
2 QUEST 911
3 CANNING 46775
3 MULTIPACK42601
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.


In reply to Variables as a variable name... (I know you shouldn't but...) by 2mths

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.