in reply to Re^2: Export and use different package in module
in thread Export and use different package in module
First, note that Library2.pm is missing the use Exporter qw(import);, so nothing is actually exported when you do use Library2;.
I suspect you added the package Library2; to Library.pm to work around that? However, the effect of doing so is that our %hash is declared in the current package, which is now Library2, so you're assigning a value to %Library2::hash, while what Library.pm is exporting is %Library::hash. Although you could change our %hash = ... into %Library::hash = ..., that's just fixing a workaround with a workaround, and the IMO much cleaner solution is to add the use Exporter qw(import); statement I mentioned above to Library2.pm, and just remove the package Library2; from Library.pm, which is then no longer needed, because now sub return_string will be exported from Library2 into Library and be callable there.
BTW, this:
use File::Basename qw(dirname); use Cwd qw(abs_path); use lib dirname(dirname abs_path $0);
Can be replaced by the more reliable:
use FindBin; use lib $FindBin::Bin;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Export and use different package in module
by chenhonkhonk (Acolyte) on Feb 22, 2019 at 20:54 UTC | |
by haukex (Archbishop) on Feb 22, 2019 at 21:11 UTC | |
by chenhonkhonk (Acolyte) on Feb 22, 2019 at 22:27 UTC | |
by haukex (Archbishop) on Feb 22, 2019 at 23:29 UTC | |
by chenhonkhonk (Acolyte) on Feb 23, 2019 at 06:10 UTC | |
|