in reply to Re: array looping with foreach
in thread array looping with foreach
There is never a need in Perl to use a C style for loop to iterate over a range like that. Instead use the safer and clearer:
for my $index (0 .. $#array) { ... }
There are situations where a C style for loop is appropriate in Perl, but they are in fact fairly rare. About the only case that readily comes to mind is where a complicated termination test is required, and even then it is often clearer to use last with a statement modifier in the body of the loop. If multiple statements need to be executed at the end of each iteration you should use a continue block rather than pile all the statements into the iteration part of a C for loop header.
|
|---|