In article
<8412cdc2-d3ec-4025-abe3->,
shul <> wrote:
>I am curious. If I take !1 and put it into an array or hash, what
>lives in that position?
The same thing as if you put it into a scalar ...
>I know that !1 is false, which can be represented by () or 0.
That can be stated more precisely. Luckily, "man perlsyn" does.
There are actually 5 things that are treated as false in a boolean
context, and !(something true) has a special value:
Truth and Falsehood
The number 0, the strings '0' and '', the empty list "()", and
"undef" are all false in a boolean context. All other values are
true. 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.
>but I dont get anything printed when I try to print
>print " the value is $arp[4]\n";
>
>it just prints
>
>"the value is "
Well, you do get something: the null string, but that's a rather
pedantic statement. In
print " the value is $arp[4]\n";
With $arp[4] in the double-quoted string, it's evaluated as a string,
so as "man perlsyn" says, "it is treated as ''".
Answers to variants you didn't ask about
:
By default, using it in print on its own is in string context too, so
$ perl -e '$x = !1; print "This false is <", $x, ">\n"'
This false is <>
But if you force a numeric context:
$ perl -we '$x = !1; print "This false is <", $x+0, ">\n"'
This false is <0>
Note the difference between that and this:
$ perl -we '$x = ""; print "This false is <", $x+0, ">\n"'
Argument "" isn't numeric in add at -e line 1.
This false is <0>
That is, !1 really is a special false, as "man perlsyn" says:
"" gives a warning message that !1 doesn't.
--
Tim McDaniel,