The questions are far too easy :)
- $a is a global that can be used without declaring it because sorting would otherwise be a pain in the but.
- += is a "don't care" operator. $a = $a + $_ would have generated a "use of uninitialized value in ..."-warning.
- See 1 and 2
- See 1 - you probably tried to avoid confusion, which is a good thing. Perhaps I should have done so to, but I could really not care less for a three-liner.
++ 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] |
1., 2. see perlman strict, chapter 'strict vars'
as in a previuos thread already mentioned :-)
$a and $b arre exempted from the strict vars pragma due to their special role in the sort function
3. undef equals to '0'
4. dunno, didn't read it yet :-)
Have a nice day
All decision is left to your taste | [reply] |
| [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] |