http://www.perlmonks.org?node_id=982696

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?