in reply to Re^5: access to hashes with same name, from different packages with same name
in thread access to hashes with same name, from different packages with same name

I am really sorry, I have now tried your recommendation, and it worked, thank you very much for your patience. Sorry for "posting-pollution" (I added an update to my previous posting that I tried it juts now).

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.
  • Comment on Re^6: access to hashes with same name, from different packages with same name

Replies are listed 'Best First'.
Re^7: access to hashes with same name, from different packages with same name
by almut (Canon) on Feb 11, 2007 at 16:56 UTC
    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

      Hi almut and Joost, I hereby confirm that your contributions helped me a lot to visualize all these stuff. All of your suggestions solved my problems. Thank you very much again.