in reply to do, local and a qualified identifier?
I thought it gave it a global symbol a local value?
It does, at run-time.
What is the purpose of the declaring $Foo::bar local?
None, unless it's used in Foo.pm's topmost level, or in a function (directly or indirectly) called from Foo.pm's topmost level.
If so, when init is called will it set the localized value like a closure or the global value?
It depends on whether someone in the call stack did local $Foo::bar. Unless &Foo::init is called from Foo.pm's topmost level (where there is such a local), probably not.
Further, what is the point of qualifying the identifier with the package name? and does that have any effect on the functionality?
Removing it will result in a compilation failure because use strict 'vars' is active. If you want to remove the need for the package quantifier, use our $bar; in scope at compile-time.
use strict; use warnings; package Foo; our $bar; # "our" is like "my", but it # creates a package variable # instead of a lexical variable. sub init { $bar = 42; # "our" removes the need to # specify the package name. } ... 1;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: do, local and a qualified identifier?
by pg (Canon) on Oct 09, 2005 at 03:22 UTC | |
by ikegami (Patriarch) on Oct 09, 2005 at 16:36 UTC |