It might help you to understand a few very basic things I
always try to teach new Perl programmers:
- With the exception of special variables defined by Perl (well, okay you can do that too ...) there really are no
"global" variables in Perl as there are in many languages. The variables you're definining in your example are package variables. Those are different than global variables.
- To access another package's package variables, you can
do one of two things:
- You can fully qualify them with the package name, as in
$packageName::variableName;
- The package defining the variables can export them in a
way that lets them become part of the namespace of another
package. That is typically done using Exporter.
The way I think of Perl's package variables is that both
the defining and using packages get to decide how "global"
to make them: the defining package by how it defines and
exports them; the using package by how it imports them.
On the importing side, the using package is really making
a decision about how it wants to pollute its own package
namespace.
In addition to Export, the documentation on
import and use should help you to understand this
better. Some people don't realize that use lets the
using package decide how much it wants to take advantage
of what the package being used has decided to Export by
default.