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


in reply to looping over multidimensional arrays

I read somewhere that if you are using counters in perl, you are not doing it right

That's probably a bit of an exaggeration to make a point: People coming from other languages will be used to C-style for loops, but often Perl's foreach will do away with a need to use indicies in the first place.

But sometimes you need an index, and there, instead of for (my $i; $i<@a; $i++), the more Perlish ways are for my $i (0..$#a) or, on newer versions of Perl, you can use each.

Note: This is a re-post of a node that was lost.