Also be aware that at least some versions of Perl are a touchy about package variables. If you split a module between two files, say "Foo_1.pm" and "Foo_2.pm", and you define a variable in "Foo_1.pm", then you have to use the fully qualified name in "Foo_2.pm", even if the current package is the same as "Foo_1.pm". This applies to both my and our variables. This issue does not apply to subroutines. They can be used without qualification in all files assigned to the "Foo" package.
Sorry, but no.
In your example try having hello() print out the value of $HELLO. You will find that Foo_2.pm did not alter it. Alternately try using our in Foo_2.pm and see that you can access the right $GOODBYE. And you really are accessing it without the fully qualified package name.
Here are the relevant facts:
- Perl has set of package tables where variables can be stored. You can access these using the fully qualified package name (eg $Foo::HELLO), or you can access the ones in the current package if they have been declared with vars, imported with Exporter, or if you're not using strict.
- Perl has an independent way to store lexical variables. These are declared with my, and do not exist in the package system. You cannot access them from outside the lexical scope where it is declared. (Well, unless you want to engage in some internals wizardry.)
- Perl has a weird hybrid declared with our. This gives lexically scoped access to a package global.
- strict.pm requires that variables be properly declared, or fully package scoped.
So here is what happened. In Foo_1.pm you declared a lexical variable $HELLO with my. And you lexically scoped access to $Foo::GOODBYE with our. In Foo_2.pm you were out of the lexical scope of the declarations in Foo_1.pm, so you silenced any possible warning by using the fully qualified package name. This gave you access to a variable named $HELLO, but the wrong one. And you got access to the expected $GOODBYE.
All of this is documented behavior.