Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
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 making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2014-12-22 12:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (116 votes), past polls