The following excerpt is taken from
Thestatement declares the compilation unit as being in the given namespace. The scope of the
packagedeclaration is from the declaration itself through the end of the enclosing block,
package, or file, whichever comes first (the same scope as the
my() operators). Unqualified dynamic identifiers will be in this namespace, except for those few identifiers that if unqualified, default to the main package instead of the current one as described below.
$v1 = "v1_val";
my $v2 = "v2_val";
The two general types of variable scope are dynamic and lexical. Basically, the visibility of lexical variables is based on their location in the source code and the visibility of dynamic variables is determined at run-time.
In Perl, variables declared with
my are lexical and any other variables are dynamic. The main place that this distinction becomes directly relevant is that
local can only be used with dynamic (non-
my) variables and not with lexical (
See also the Perl FAQ, What's the difference between dynamic and lexical (static) scoping?