3. undef equals to '0'
No.
undef evaluates to 0 in numeric context, to an empty string in string context. In boolean context, it is false. However, undef + 0 would eq '0', because first 0 + 0 is calculated, and then the result (0) is put in string context, and will be the string 0, which is in every way identical to 0 :)
When undef is used with a numeric (+, -, * etcetera) or string operator (., x, =~, etc) that is not an assignment (+=, -=, ++, etc) itself, a warning will be emitted.
++ vs lbh qrpbqrq guvf hfvat n ge va Crey :)
Nabgure bar vs lbh qvq fb jvgubhg ernqvat n znahny svefg.
-- vs lbh hfrq OFQ pnrfne ;)
- Whreq
| [reply] |
Read question 2 more carefully.
Question 1 has to do
with $a passing "use strict" for the reason you
offer.
But question 2 has to do with warnings on math with undef
values. Although $a passes
strict in this puzzle, it is still undef at the point
we first encounter it.
Just about any kind of math
on such a value will not abort (as happens with the
use strict violation referred to in Q. 1), but it normally
does produce a warning (if warnings are turned on)
e.g.:
$a = $a + 1; # warns but executes anyway
print $a; # 1
In this case,
the warning is: "Use of uninitialized value in
addition (+) at testprog.pl line xx.".
So question 2 is: Why is such a warning not produced in
the snippet meryln refers to. | [reply] [d/l] |