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

Cody Fendant has asked for the wisdom of the Perl Monks concerning the following question:

I want to do this:

use Foo; my $object = Foo->new();

Only I want to replace 'Foo' with a variable determined by some other factor.

my $module_name = 'Foo'; use $module_name; my $object = $module_name->new();

I got as far as understanding that use will never be happy with this, is that right? And I ought to use require instead?

My code doesn't give an error if I do this:

$module = 'Foo'; my $module_path = $module . '.pm'; require $module_path;

But it complains that I'm calling "new" on an unblessed reference when I do my $object = $module->new(); on the next line.