Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
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;