Although it doesn't make a lot of sense to discuss Perl solutions when the first comment suggests one that's unlikely to be beaten in efficiency, just for the TIMTOWTDI of it here's another slow one:
$pos = do{ my @h{reverse @a} = (reverse 0..$#a); $h{$elem}};If it doesn't matter when duplicate elements are found in their last instead of first position, you can omit the reverse.
In reply to Re: Finding the index of a specific element in an array.
by mbethke
in thread Finding the index of a specific element in an array.
by Thakur
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |