DigitalKitty has asked for the wisdom of the Perl Monks concerning the following question:
Hi all.
I was recently experimenting with a few perl related topics and I felt as though I might benefit from some clarification. In the following code sample:
The output seems to indicate that a lexical variable (i.e. $var) is not associated with package level scope. I was able, however, to display the value of $var (15) by omitting the name of the initial package (Test). Only after using the package level 'qualifier' (our) was I able to obtain the value $var by prepending the package name.
Furthermore, there doesn't appear to be any safeguard that will prevent an interloper from creating subroutines within the namespace of neighboring (or distant) packages. Any feedback on these issues would be appreciated.
Thanks,
-Katie
I was recently experimenting with a few perl related topics and I felt as though I might benefit from some clarification. In the following code sample:
#!/usr/bin/perl -w use strict; package Test; my $var = 15; package Test2; print $Test::var; print $var;
The output seems to indicate that a lexical variable (i.e. $var) is not associated with package level scope. I was able, however, to display the value of $var (15) by omitting the name of the initial package (Test). Only after using the package level 'qualifier' (our) was I able to obtain the value $var by prepending the package name.
Furthermore, there doesn't appear to be any safeguard that will prevent an interloper from creating subroutines within the namespace of neighboring (or distant) packages. Any feedback on these issues would be appreciated.
Thanks,
-Katie
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Packages, scope, and lexical variables
by Zaxo (Archbishop) on Mar 08, 2005 at 07:13 UTC | |
Re: Packages, scope, and lexical variables.
by ikegami (Patriarch) on Mar 08, 2005 at 07:15 UTC | |
by ysth (Canon) on Mar 08, 2005 at 08:54 UTC | |
by ikegami (Patriarch) on Mar 08, 2005 at 15:03 UTC | |
Re: Packages, scope, and lexical variables
by merlyn (Sage) on Mar 08, 2005 at 13:55 UTC | |
Re: Packages, scope, and lexical variables
by manav (Scribe) on Mar 08, 2005 at 08:12 UTC |
Back to
Seekers of Perl Wisdom