I
Ilya Zakharevich
I managed to confuse myself in a teaspoon... Consider
perl -wle "my $x; BEGIN{ $x=12 } print $x"
12
I would expect it to warn that $x is uninitialized, and print
nothing. The reasoning goes like that:
AT COMPILE TIME:
`my' is seen; after this $x is considered as lexical
BEGIN is compiled and executed; $x becomes 12
`print' is compiled
AT RUN TIME
`my' is executed. [*] Variable $x becomes undef
`print' is executed
Apparently, [*]-action is not executed in this context. The question
is: why? Is it documented?
Puzzled,
Ilya
perl -wle "my $x; BEGIN{ $x=12 } print $x"
12
I would expect it to warn that $x is uninitialized, and print
nothing. The reasoning goes like that:
AT COMPILE TIME:
`my' is seen; after this $x is considered as lexical
BEGIN is compiled and executed; $x becomes 12
`print' is compiled
AT RUN TIME
`my' is executed. [*] Variable $x becomes undef
`print' is executed
Apparently, [*]-action is not executed in this context. The question
is: why? Is it documented?
Puzzled,
Ilya