Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2016-06-28 03:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred method of making French fries (chips) is in a ...











    Results (349 votes). Check out past polls.