I thought that was the point! We try to be Perlish because this isn't language X. Perhaps our definitions of "Perlish" differ.
There really is no truly Perlish idiom for this situation. The idiom in OP's second example has some benefits: it's simple, doesn't require any extra modules, is hard to screw up, and lets you safely insert or delete from your array.
But -- playing language designer for a moment -- could it be better?
for my $i (0..$#array) {
my $el = $array[$i];
...
};
Hmm, too much repetition. Perhaps:
over (@array) as ($el; $i) {
...
};
The array element and the index are implicitly localized to the loop, and the index is optional. If you want to iterate n-at-a-time you can do:
over (@array) as ($el_a, $el_b; $i, $j) {
...
};
|