in reply to About packages and scopes

To further clear (muddy??) the waters, it seems that you're asking about scoping as it relates specifically to packages. A package is nothing more or less than a new namespace. A namespace is nothing more than a hash, called a symbol table, that contains, as its members, references to all the non-lexical variables within the namespace. In fact, the definition of being within in a namespace is to be contained within that specific hash. (For the curious, the hash for a namespace 'Foo::Bar' is %Foo::Bar::, so you can iterate over it, etc.)

A lexical variable is a variable that is accessible only within its inner-most enclosing scope. It's declared using my and cannot be accessed outside that scope. Period. Now, a variable declared with my at a file level is considered to be withing the implicit scope of the package. Still unaccessible outside that scope. (Closures are an indirect access to a lexical variable, so aren't really part of this discussion.)

Variables that are either not declared at all or declared with our or local are inserted into the symbol table of that namespace. If declared, they're considered to be block-scoped globals. The primary difference, simply put, between our and local is that our is 5.6+, but works under strict vars. local does not. (There's more to it than that, but look around the Monastery and you'll find more on it than you'll ever want to know.)

What does all this have to do with packages? Well, if you want to access a variable declared in package Foo from package Bar, you have to make sure you either are not using strict vars (Bad idea!!!) or have declared your variables with our. At this point, you can do a number of things.

  1. Use Exporter. Read up on the documentation how this would work.
  2. Use the fully-qualified name. $Foo::MyVar or something like that.
  3. Make Foo a class and create a method to access it.
I hope this helps.

------
We are the carpenters and bricklayers of the Information Age.

Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.