in reply to Re^4: Finding the index of a specific element in an array.
in thread Finding the index of a specific element in an array.

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:


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?

Replies are listed 'Best First'.
Re^6: Finding the index of a specific element in an array.
by chromatic (Archbishop) on Jan 25, 2012 at 19:43 UTC
    ... once you add code to remember the index for use after the loop -- and omit the say ...

    Sure, but that's different than the code JavaFan posted. If I were to write code to save the index after the loop, I'd write it more like the code you wrote (minus the potential infinite loop) or with something from one of the List::*Util family, like other people wrote.

    Even so, it's still less synthetic once you count tokens and the possibility of writing the wrong code.