Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

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

by LanX (Canon)
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


Comment on Re^2: How to check whether my array contains element x
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2014-08-21 05:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (127 votes), past polls