Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Looping on Array of Arrays (by References)

by ikegami (Pope)
on Sep 26, 2011 at 18:32 UTC ( #927925=note: print w/ replies, xml ) Need Help??


in reply to Looping on Array of Arrays (by References)

By blindly changing "AoA" to "{$AoAref}",

for my $i (0 .. $#AoA){ my $aref = $AoA[$i]; print "array is: $AoA[$i]\n"; $arg1 = $AoA[$i] if $AoA[$i][0] == "160001"; $arg2 = $AoA[$i] if $AoA[$i][0] == "170001"; $arg3 = $AoA[$i] if $AoA[$i][0] == "670002"; }
becomes
for my $i (0 .. $#{$AoAref}){ my $aref = ${$AoAref}[$i]; print "array is: ${$AoAref}[$i]\n"; $arg1 = ${$AoAref}[$i] if ${$AoAref}[$i][0] == "160001"; $arg2 = ${$AoAref}[$i] if ${$AoAref}[$i][0] == "170001"; $arg3 = ${$AoAref}[$i] if ${$AoAref}[$i][0] == "670002"; }
We can clean this up, some, though.
for my $i (0 .. $#$AoAref){ my $aref = $AoAref->[$i]; print "array is: $AoAref->[$i]\n"; $arg1 = $AoAref->[$i] if $AoAref->[$i][0] == "160001"; $arg2 = $AoAref->[$i] if $AoAref->[$i][0] == "170001"; $arg3 = $AoAref->[$i] if $AoAref->[$i][0] == "670002"; }
or if you actually use the $aref you created,
for my $i (0 .. $#$AoAref){ my $aref = $AoAref->[$i]; print "array is: $aref\n"; $arg1 = $aref if $aref->[0] == "160001"; $arg2 = $aref if $aref->[0] == "170001"; $arg3 = $aref if $aref->[0] == "670002"; }
And to get rid of useless $i:
for my $aref (@$AoAref) { $arg1 = $aref if $aref->[0] == "160001"; $arg2 = $aref if $aref->[0] == "170001"; $arg3 = $aref if $aref->[0] == "670002"; }


Comment on Re: Looping on Array of Arrays (by References)
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://927925]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (10)
As of 2015-07-03 16:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (53 votes), past polls