APM: using a scalar var as a module
Mike South
msouth at shodor.org
Tue Nov 25 22:55:40 CST 2003
hi jeremy,
here's some relevant stuff that you can get from "perldoc -f require":
n other words, if you try this:
require Foo::Bar; # a splendid bareword
The require function will actually look for the "F<Foo/Bar.pm>"
file in the directories specified in the C<@INC> array.
But if you try this:
$class = 'Foo::Bar'; require $class; # $class is not
# a bareword
#or
require "Foo::Bar"; # not a bareword because of the ""
The require function will look for the "F<Foo::Bar>" file in the
@INC array and will complain about not finding "F<Foo::Bar>" there.
In this case you can do:
eval "require $class";
What I do is that eval, then I check $@ and die with that if it's
nonempty. Or something like that. If that doesn't work reply and
I'll look it up.
mike
More information about the Austin
mailing list