Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: boolean IN(); function in perl like

by adamk (Chaplain)
on Jan 17, 2005 at 03:50 UTC ( [id://422655]=note: print w/replies, xml ) Need Help??


in reply to Re: boolean IN(); function in perl like
in thread boolean IN(); function in perl like

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

Replies are listed 'Best First'.
Re^3: boolean IN(); function in perl like
by Errto (Vicar) on Jan 17, 2005 at 04:31 UTC

    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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://422655]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (2)
As of 2024-04-26 03:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found