Each example must be run separately. You're getting the value of $x defined from the previous test. If you run the 2nd one by itself, however:
$ perl -le ' BEGIN { my $x = 1; } print defined $x ? "defined" : "undefined";' undefined
And with strict:
$ perl -Mstrict -le ' BEGIN { my $x = 1; } print $x;' Global symbol "$x" requires explicit package name at -e line 2. Execution of -e aborted due to compilation errors.
In reply to Re^3: Scope, package, and 'my' variables
by revdiablo
in thread Scope, package, and 'my' variables
by ff
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |