Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Getting Matching Items From An Array

by Limbic~Region (Chancellor)
on Jul 05, 2004 at 16:51 UTC ( [id://371938]=perltutorial: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    my %lookup = map { $_ => undef } @array;
    print "There it is\n" if exists $lookup{foo};
    
  2. or download this
    my %lookup = map { $array[$_] => $_ } 0 .. $#array;
    my $index = $lookup{foo};
    
  3. or download this
    my @indices = grep { $array[$_] eq 'foo' } 0 .. $#array;
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2024-03-28 19:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found