Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: check if a value is in a given set

by Anonymous Monk
on Jul 24, 2012 at 15:33 UTC ( [id://983438]=note: print w/replies, xml ) Need Help??


in reply to check if a value is in a given set

Smart-matching seems to work OK.

use 5.010; my @set = qw/banana plum apple strawberry pear/; my $var = "apple"; if ($var ~~ @set) { say "yes"; }

There are also hashes which might be a tad faster if your set is large.

my %set = map { $_ => 1 } qw/banana plum apple strawberry pear/; if (exists $set{$var}) { say "yes"; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2024-04-18 11:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found