What's the difference b/w the 2 ways to load a module dynamically?
=any
eval qq(
use $$category_r[0];
);
die $? if $?;
=cut
require "$$category_r[0].pm";
Now only require
is working for me,I don't know why the 1st one doesn't work as expected..开发者_StackOverflow社区.
Even this is not working:
my $pkg = "A";
eval {
use $pkg;
};
Try Module::Load if you want to load modules on the fly.
It works for both filenames and modules. It is safer than
my $module = "strict; warn 'PWNED'";
eval "use $module";
Also, as @daxim points out, it explains what's going on.
You should be checking $@
, not $?
. Is this the actual code that doesn't work? Presumably you don't have it enclosed in pod for real.
For use, $$category_r[0]
should be something like Module::Name
, while your require is expecting Module/Name
.
精彩评论