for my $i (0 .. $#array) { next unless $array[$i] == 7; say "The index is $i"; }
You may quibble that the use of $#array is itself an artifact of the method I've chosen to solve the problem (and I can agree), but there's less synthetic code in this version. Certainly there's iteration and incrementing, but when Perl handles that and the programmer doesn't have to, there's less synthetic code.
In reply to Re^4: Finding the index of a specific element in an array.
by chromatic
in thread Finding the index of a specific element in an array.
by Thakur
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |