Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: Perl Idioms Explained - !!expr

by broquaint (Abbot)
on Jul 14, 2004 at 13:17 UTC ( #374293=note: print w/ replies, xml ) Need Help??


in reply to Re: Perl Idioms Explained - !!expr
in thread Perl Idioms Explained - !!expr

return grep { $_ eq $_[0] } @_[ 1 .. $#_ ];
Depending on context this will return different things, whereas !!expr will always return a boolean value.
return ~~grep { $_ eq $_[0] } @_[ 1 .. $#_ ];
This will return the number of elements returned by grep as opposed to !!expr which, again, will return a boolean value.

Of course both of the above are valid in appropriate situations, but if you just want a boolean value then !!expr is an appropriate idiomatic solution.

HTH

_________
broquaint


Comment on Re^2: Perl Idioms Explained - !!expr
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (19)
As of 2014-07-11 17:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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








    Results (232 votes), past polls