in reply to better way to find list members?
@animals = qw(cat dog bat rat gerbil snake pig chicken); foreach (@animals) { $animals{$_}++; } # initialize %animals hash # use a hash if (exists $animals{'pig'}) { print "We have a pig!\n"; } # use grep if (grep { $_ eq 'snake'} @animals) { print "We have a snake!\n"; } # use a for loop for (@animals) { last if $_ eq 'dog'; } print "We have a dog!\n";
Cheers,
KM
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Re: better way to find list members?
by DrManhattan (Chaplain) on Oct 18, 2000 at 03:35 UTC | |
by runrig (Abbot) on Oct 18, 2000 at 03:58 UTC | |
by myocom (Deacon) on Oct 18, 2000 at 03:38 UTC | |
|
RE: Re: better way to find list members?
by runrig (Abbot) on Oct 18, 2000 at 03:56 UTC |