Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: boolean IN(); function in perl like

by premchai21 (Curate)
on Jan 15, 2005 at 06:01 UTC ( #422463=note: print w/replies, xml ) Need Help??


in reply to boolean IN(); function in perl like

I'm surprised no one mentioned List::Util's "first" routine yet.

first {$_ eq $e} @a

I'm not sure this works properly if $e is undef, though.

Replies are listed 'Best First'.
Re^2: boolean IN(); function in perl like
by adamk (Chaplain) on Jan 17, 2005 at 03:50 UTC
    Or List::MoreUtil's even more correct 'any' function.
    if ( any { $_ eq $foo } @list ) { }
    If you are wondering why first isn't enough, imagine...
    if ( first { ! defined $_ } @list ) { # Does not get called if it matches } if ( any { ! defined $_ } @list ) { # Does get called it if matches }
    Of course, this assumes you only need to check once and once only. If you want to check many times, build the hash index and do it that way.

    Edit by castaway - swapped lotsa br tags for code tags

      Very right. ++ At a more basic level, this is why exists exists. Things may be there but have false values.

      Btw, please use <code> tags instead of <pre> tags when posting code. Cheers.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://422463]
help
Chatterbox?
[MidLifeXis]: Project Admin, a while ago: "No, I would prefer you didn't close that ticket yet confirming $vendor's support process yet. Continue to periodically check back to see if it has changed."...
[MidLifeXis]: Project Admin, today, after many periodic updates from me: "Why hasn't this been closed yet? Is there anything I can do to get this closed?" <facepalm>
[MidLifeXis]: In addition to SOAP (last hour of cb), try water. ;-)

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (10)
As of 2017-01-19 12:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (170 votes). Check out past polls.