Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
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


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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (13)
As of 2015-07-29 16:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (265 votes), past polls