http://qs1969.pair.com?node_id=854828


in reply to How do I find the index of a specific array value?

You should use first() from List::Util. List::Util is a core module, unlike List::MoreUtils and other modules mentioned above, so it is portable and can be used with no extra effort.

use List::Utils qw(first); my @array = qw( Apples Oranges Brains Toes Kiwi); my $search = "Toes"; my $index = first {$_ eq $search} @array; print "index of $search = $index\n";

Replies are listed 'Best First'.
Re: Answer: How do I find the index of a specific array value?
by myuserid7 (Scribe) on Aug 13, 2010 at 05:32 UTC
    I meant
    use List::Utils qw(first); my @array = qw( Apples Oranges Brains Toes Kiwi); my $search = "Toes"; my $index = first {$array[$_] eq $search} 0..$#array; print "index of $search = $index\n";