jdlev has asked for the wisdom of the Perl Monks concerning the following question:
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:
What syntax would I use to pull out the 'Name' for '114'? to have the program return 'Melissa'?'113' => { 'Name'=>'John', 'Age'=>'33', 'Sex'=>'Yes Please' }, '114' => { 'Name'=>'Melissa', 'Age'=>'25', 'Sex'=>'No Way' }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How To Print Single Element From Nested Hashes? (simple answer)
by tye (Sage) on Sep 11, 2013 at 00:41 UTC | |
|
Re: How To Print Single Element From Nested Hashes?
by AnomalousMonk (Archbishop) on Sep 11, 2013 at 01:08 UTC | |
|
Re: Dynamic Variables?
by tobyink (Canon) on Sep 10, 2013 at 23:14 UTC | |
|
Re: Dynamic Variables?
by Anonymous Monk on Sep 10, 2013 at 22:19 UTC |