Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
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 taking refuge in the Monastery: (8)
As of 2014-10-20 10:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (75 votes), past polls