http://www.perlmonks.org?node_id=1053366

jdlev has asked for the wisdom of the Perl Monks concerning the following question:

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