Hi again guys. I really am sorry about asking so many questions, but really appreciate the help...

So right now, in my program I have basically have a ton of data that repeats itself, and I'm trying to condense it to speed it up. It get's the same stats on every player. PlayerID, Position, Salary, PointsPerGame...I'm trying to figure out how to explain this, so bear with me because I'm utterly confused...

I have a foreach loop that iterates through a DBI produced Hash. It does it based on the players position. So basically, it looks kind of like this:

foreach $QB1(sort keys $Hash) { $QB1 = $points; foreach $QB2 (sort keys $Hash) { $QB2 = $points; foreach $RB1 (sort keys $Hash) { $RB1 = $points; foreach $RB2 (sort keys $Hash) { $RB2 = $points; }#end $RB2 foreach loop }#end $RB1 foreach loop }#end $QB2 foreach loop }#end $QB1 foreach loop

Now I know I should be able to condenses 10 foreach loops into a single one, but how? Should I use some type of subroutine? Dynamic Variables fed by arrays?

How would I make dynamic variables where on the iterations through the formula, the variable name is updated. So for instance, the first time through, the variable would be set to $QB1, the second time through, it would be set to $QB2...and so on?

Thanks for any help once again :)

Update

Let's say a hash has the following structure:

'113' => { 'Name'=>'John', 'Age'=>'33', 'Sex'=>'Yes Please' }, '114' => { 'Name'=>'Melissa', 'Age'=>'25', 'Sex'=>'No Way' }
What syntax would I use to pull out the 'Name' for '114'? to have the program return 'Melissa'?

I love it when a program comes together - jdhannibal

In reply to How To Print Single Element From Nested Hashes? by jdlev

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.