The output seems to indicate that a lexical variable (i.e. $var) is not associated with package level scope.
Correct. By definition, lexicals are block scoped and in no way related to packages. The file is considered a block for this purpose.
If you want $Test::var to work, change my to our, making $var a package variable instead of a lexical.
Furthermore, there doesn't appear to be any way to prevent an interloper from creating subroutines within the namespace of neighboring (or distant) packages.
That's true, but I haven't known this to be a problem. Any of the following three lines of code would create a sub named new_sub in the package Test, no matter which file contained the code.
{ package Test; sub new_sub { ... } } -or- sub Test::new_sub { ... } -or- *Test::new_sub = sub { ... };
In reply to Re: Packages, scope, and lexical variables.
by ikegami
in thread Packages, scope, and lexical variables
by DigitalKitty
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |