J
J Krugman
I've spent more hours than I care to admit trying to understand
the difference between Perl's use and require, and I discovered
today that all this effort has been a miserable waste of time,
because use and require *still* confound my attempts at coding.
For example.
I have a method "a" in package A that must invoke a class method
"b" from a package B, and the identity of package B is not known
until runtime.
package A;
#...
sub a {
my ($self, $package) = @_;
# use B;
eval { "require $package; 1" } or die "Have a cow";
$package->b;
}
In the form above, perl dies with a message "Can't locate object
method "b" via package "B" (perhaps you forgot to load "B"?)". If
I uncomment the "use B;" statement (and comment out the eval line),
the code runs fine, but of course this solution is not acceptable,
because I can't hard-code the package name.
I don't understand why perl will load B (via the eval'ed require
statement) without any errors, and still fail to find method b in
B. What gives?
TIA!
jill
the difference between Perl's use and require, and I discovered
today that all this effort has been a miserable waste of time,
because use and require *still* confound my attempts at coding.
For example.
I have a method "a" in package A that must invoke a class method
"b" from a package B, and the identity of package B is not known
until runtime.
package A;
#...
sub a {
my ($self, $package) = @_;
# use B;
eval { "require $package; 1" } or die "Have a cow";
$package->b;
}
In the form above, perl dies with a message "Can't locate object
method "b" via package "B" (perhaps you forgot to load "B"?)". If
I uncomment the "use B;" statement (and comment out the eval line),
the code runs fine, but of course this solution is not acceptable,
because I can't hard-code the package name.
I don't understand why perl will load B (via the eval'ed require
statement) without any errors, and still fail to find method b in
B. What gives?
TIA!
jill