Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Getting Matching Items From An Array

by Limbic~Region (Chancellor)
on Jul 05, 2004 at 16:51 UTC ( #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
Node Status?
node history
Node Type: perltutorial [id://371938]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2014-07-12 13:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (240 votes), past polls