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


in reply to Re^2: require mystery
in thread require mystery

No:

require $pathtool;

is exactly the same as

require "File::Path";

which fails. Your other attempt,

eval "require $pathtool";

evaluates the string, which then looks like

require File::Path;

which succeeds. Consider using the following code if you want a dynamic module loader:

sub require_package { for (@_) { (my $file = $_) =~ s-::|'-/-g; require "$file.pm"; }; };

Other alternatives which I recommend against are UNIVERSAL::require and Module::Load because they both hide fatal errors from you, for example compilation errors in the required modules.

Maybe you might want Module::Pluggable for a plugin system.