Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

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

Comment on Re: how ! operator works
Select or Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2015-10-04 20:55 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (104 votes), past polls