Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
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 studying the Monastery: (7)
As of 2014-07-11 10:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (224 votes), past polls