Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
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 pondering the Monastery: (18)
As of 2014-08-20 15:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (116 votes), past polls