perl -wMstrict -e "$::x=0; $x++" # not OK
perl -wMstrict -e "package foo; $foo::x=0; $x++" # not OK
####
perl -wMstrict -e "BEGIN{*::x=\$a} $x++" # not OK (1)
perl -wMstrict -e "BEGIN{package foo; *::x=\$a} $x++" # OK (2)
##
##
perl -wMstrict -e "{package foo; *::x=\$a} $x++" # not OK
##
##
C:\>perl -MO=Deparse -wMstrict -e "{package foo; *::x=\$a} $x++"
Variable "$x" is not imported at -e line 1.
Global symbol "$x" requires explicit package name (did you forget to declare "my
$x"?) at -e line 1.
-e had compilation errors.
BEGIN { $^W = 1; }
use strict;
{
package foo;
*main::x = \$a;
}
$main::x++;
##
##
perl -wMstrict -e "BEGIN{package bar; *bar::x=\$a} package bar; $x++" # not OK
perl -wMstrict -e "BEGIN{package foo; *bar::x=\$a} package bar; $x++" # OK