Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: how ! operator works

by ikegami (Pope)
on Feb 04, 2011 at 08:44 UTC ( #886156=note: print w/replies, xml ) Need Help??


in reply to how ! operator works

But, when I do !1, it is neither returning 0 nor undef.

Those aren't the only false values. For example, an empty string is also false. It's not exactly an empty string being returned, though.

It shouldn't matter to you at all what it returns as long as it's false, but the value it happens to return is zero in numeric contexts and the empty string in string contexts.

>perl -wE"say ''.!1" >perl -wE"say 0+!1" 0

If it was just zero, the result would be different:

>perl -wE"say ''.0" 0 >perl -wE"say 0+0" 0

If it was just the empty string, the result would be different:

>perl -wE"say ''.''" >perl -wE"say 0+''" Argument "" isn't numeric in addition (+) at -e line 1. 0

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://886156]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2016-12-04 11:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (64 votes). Check out past polls.