Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Comparing a value to a list of numbers (in via hash)

by LanX (Cardinal)
on Jan 29, 2021 at 16:52 UTC ( #11127647=note: print w/replies, xml ) Need Help??


in reply to Comparing a value to a list of numbers

TIMTOWTDI

Depending on your requirements on time and memory complexity, you could also use a hash

DB<28> %in = map { $_ => 1 } 1,2,5,6,9,10,41..56 DB<29> p $in{5} 1 DB<30> p $in{0} DB<31>

update

corrected C&P error omitting the 1

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2021-06-13 02:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (54 votes). Check out past polls.

    Notices?