Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: *IN* Operator for the Perl wish list

by educated_foo (Vicar)
on Mar 30, 2007 at 14:47 UTC ( [id://607489]=note: print w/replies, xml ) Need Help??


in reply to *IN* Operator for the Perl wish list

You can also just do
grep $_ == $value, 1,5,21,99;
which isn't much more typing.

Replies are listed 'Best First'.
Re^2: *IN* Operator for the Perl wish list
by liz (Monsignor) on Mar 30, 2007 at 16:31 UTC
    Rather than "grep", I would use List::Util's "first" function, because that short-circuits on the first match, rather than always trying all of the elements.

    Liz

      I haven't benchmarked it, but I suspect first has significantly more overhead, so might only be of benefit for long lists. I'd be interested in seeing a benchmark.

      Update: yes, I mean even the XS version

        Not necessarily -- List::Util has XS versions of all its functions.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-04-19 23:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found