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;
In reply to Re^3: Export and use different package in module
by haukex
in thread Export and use different package in module
by chenhonkhonk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |