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";
}

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 rifling through the Monastery: (18)
As of 2016-08-31 17:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
The best thing I ever won in a lottery was:

Results (433 votes). Check out past polls.