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

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 avoiding work at the Monastery: (4)
As of 2015-11-29 05:23 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (747 votes), past polls