I down voted this because: once you add code to remember the index for use after the loop -- and omit the say :
my $pos; for my $i (0 .. $#array) { next unless $array[$i] == 7; $pos = i; last; } ## do something with $pos.
-- your code is at least as synthetic (by the standard of mjd's articles) as JavaFan's, if not more so:
In reply to Re^5: Finding the index of a specific element in an array.
by BrowserUk
in thread Finding the index of a specific element in an array.
by Thakur
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |