http://www.perlmonks.org?node_id=655575


in reply to Finding index of an entry in an Array

if you are doing a sufficiently large number of look-ups in the  @repo array, it will be advantageous to do a cached look-up of the index. (this will be all the more true if the array is large.)

perl -wMstrict -e "my @repo = qw(foo bar qux bar zot); my %repo_index; $repo_index{$repo[$_]} = $_ for reverse 0 .. $#repo; print $repo_index{bar};" 1

note that if there are duplicate entries in the array, the index of the first (lowest index) entry will be returned. eliminate the  reverse call to have it the other way.