Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: How to check whether my array contains element x

by LanX (Chancellor)
on Jan 17, 2013 at 13:15 UTC ( #1013777=note: print w/replies, xml ) Need Help??


in reply to Re: How to check whether my array contains element x
in thread How to check whether my array contains element x

You forgot to mention hashes! =)

DB<101> sub in { my ($entity, @array) = @_; my %hash; @hash{@array}=(); return exists $hash{$entity}; } DB<102> in(5,0..10) => 1 DB<103> in(42,0..10) => ""

but I wouldn't pass @array as a flat list.

Cheers Rolf

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1013777]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2017-01-22 16:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (188 votes). Check out past polls.