Please Note:
Our is not yet supported in perl 5.005.05. This version is commonly distributed on Solaris 8 (and other places).
If you find yourself in this situation, and think you need to declare a global then try this:
use vars qw(%friends);
If you would like to avoid globals ( this is common wisdom) you might consider defining a subroutine to return your values:
sub getFriends {
# Initializes my little hash
our %friends = (Paul => 1, Suzie => 1);
return %friends;
}
then you can do this in your main code
use Friends;
my %friends = &getFriends(); # for lexical scope
If you want to happily ignore scopes, you can do this in your main file:
require "outsidefile";
print %friends;
in outsidefile:
#
# guess what? I'm in main's scope !!!
#
%friends = (Paul => 1, Suzie => 1);
This is BAD, and strict will complain about this.
Can anyone explain how to properly create two files that share the same package name (name space) that works under strict?
-------------------------------------
Nothing is too wonderful to be true
-- Michael Faraday |