Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
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 browsing the Monastery: (14)
As of 2014-08-27 14:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (238 votes), past polls