http://www.perlmonks.org?node_id=522234


in reply to How does strict determine if something is legally declared?

There's a bit that gets set when you 'import' a variable and this bit tells 'strict' that the variable has been 'declared'. use vars simply 'imports' the variable.

The heuristic that perl uses to detect when a variable is being 'imported' is to detect when the variable slot of a glob gets assigned to by code compiled into another package. Note that the importing has to be done before the code that uses the imported variable is compiled.

> perl -w use strict; BEGIN { *x= \$foo::y; } print $x; Variable "$x" is not imported at - line 3. __END__ Global symbol "$x" requires explicit package name at - line 3. Execution of - aborted due to compilation errors. > perl -w use strict; BEGIN { package foo; *main::x= \$foo::y; } print $x; __END__ Name "foo::y" used only once: possible typo at - line 2. Use of uninitialized value in print at - line 3.

- tye