Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
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 chilling in the Monastery: (4)
As of 2014-11-27 21:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (188 votes), past polls