Re: !!!1 is nothing?

[email protected] Mon, 4 May 2026 11:28:57 +0200 (CEST)
Newsgroups gmane.comp.lang.perl.beginners
Message-ID <[email protected]>
[email protected]:
...
> Is there some kind of wierd evaluating of '!!1'
> or '!!0' going on?

 No.

>  Even '!!!1' should evaluate to 0 and not to nothing.
...

 
 No, undef, "" and 0 are all perl legal false values.

 From `man perldata` under headng "Scalar values", 3rd paragraph:

 «A scalar value is interpreted as FALSE in the Boolean sense if it is
 undefined, the null string or the number 0 (or its string equivalent, "0"),
 and TRUE if it is anything else.  The Boolean context is just a special kind
 of scalar context where no conversion to a string or a number is ever
 performed.  Negation of a true value by "!" or "not" returns a special false
 value.  When evaluated as a string it is treated as "", but as a number, it
 is treated as 0.  Most Perl operators that return true or false behave this
 way.»

 I.e. !1 depends on the context, if numeric it is 0, if string it is "":

$ perl -e 'print !1 + 0, "\n"'
0
$ perl -e 'print !1 . "", "\n"'

$

Regards,
/Karl Hammar



-- 
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/