I am using
$foo = 'bar';
$BAR::foo = 'bar';
When you fully specify the namespace in which a variable belongs,
perl assumes you know what you are doing. See
This generates a compile-time error if you access a variable that was neither explicitly declared (using any of
use vars) nor fully qualified.
I don't think there is a way to detect that you have specified a non-existent variable
$BAR::foo. However, if the
BAR package is under your control, you can avoid using package variables in the first place by mediating access to the state of
foo using accessors, and hiding the variable from other modules.
The answer to problems created by using global variables is not to use global variables.