temporal has asked for the wisdom of the Perl Monks concerning the following question:
I want to require and import a module based on the contents of a variable. Something like this:
use Symbol 'delete_package'; foreach (@modules) { require "sub/$_.pm"; import $_ qw(foo bar); foo(); bar(); #cleanup delete_package($_); }
Initially I wanted to use the variable, but it turns out that variables are not valid arguments.
Anyway, the require works but the import claims that it is called on an 'undefined value'. I'm not really sure why this is, the variable is definitely defined. I suspect it is having issues translating the string in the variable to a package name to import from.
If I explicitly import the first module: import FirstModule qw(foo bar); it works fine for that module.
How can I get this sort of functionality working?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: require & import $module_name
by chromatic (Archbishop) on Jul 19, 2012 at 19:41 UTC | |
Re: require & import $module_name
by CountZero (Bishop) on Jul 19, 2012 at 20:01 UTC | |
Re: require & import $module_name
by tobyink (Canon) on Jul 19, 2012 at 19:45 UTC | |
Re: require & import $module_name
by ikegami (Patriarch) on Jul 20, 2012 at 05:25 UTC | |
Re: require & import $module_name
by temporal (Pilgrim) on Jul 19, 2012 at 20:13 UTC | |
by chromatic (Archbishop) on Jul 19, 2012 at 20:53 UTC | |
Re: require & import $module_name
by cavac (Parson) on Jul 19, 2012 at 23:14 UTC |
Back to
Seekers of Perl Wisdom