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        

  • Comment on Re: How does strict determine if something is legally declared? (import)
  • Download Code

Replies are listed 'Best First'.
Re^2: How does strict determine if something is legally declared? (import)
by haukex (Bishop) on Feb 23, 2019 at 14:24 UTC

      It's a good question. I strongly recommend you post a new SoPW root node.

      I reckon we are the only monastery ever to have a dungeon stuffed with 16,000 zombies.
      What? Strict docs or vars docs/source