Is this the only way to access the package contents? I do not
permission to change the package namespaces (ie. package my_package; ->
package dir_two::my_package; ). I want to leave these stuff untouched.
Ok, if you can't (or don't want to) change the .pm files you
could try something like:
use Data::Dumper;
use vars qw(%my_package::my_hash);
sub my_special_require ($) {
my $pkg = shift;
require $pkg;
# alias %my_package::my_hash to %main::my_hash (aka %my_hash)
*my_hash = \%my_package::my_hash;
}
my_special_require "dir_one/my_package.pm";
print Dumper(\%my_hash);
my_special_require "dir_two/my_package.pm";
print Dumper(\%my_hash);
Or, simply access the hash from within your script fully qualified as
%my_package::my_hash
Update: added use vars ... to make it run cleanly with -w
|