Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: without looping, check if $var is found in @list

by imp (Priest)
on Dec 14, 2006 at 02:11 UTC ( #589719=note: print w/replies, xml ) Need Help??


in reply to without looping, check if $var is found in @list

There are a variety of ways to check for membership in a list, but the one that is right for your situation depends on the problem you are trying to solve.

For common approaches see the faq.

Update
Perl 6 will provide the any junction, which you can play with using the Perl6::Junction module for now.

use Perl6::Junction qw/ any /; if (any(@list) eq $var) { }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2016-10-01 18:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?






    Results (3 votes). Check out past polls.