Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: How do I find the index of a specific array value?

by myuserid7 (Scribe)
on Aug 13, 2010 at 05:34 UTC ( [id://854830]=note: print w/replies, xml ) Need Help??


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

You should use first() from List::Util. It 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::Util 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";

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://854830]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-04-16 13:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found