Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
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 drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2014-11-23 20:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (134 votes), past polls