in reply to How to dynamically load modules
You can do
$mod = 'My::Module1'; eval "use $mod";
which is the same as
$mod = 'My::Module1'; ($mod_file = $mod) =~ s{::}{/}g; $mod_file .= '.pm'; require $mod_file; $mod->import if $mod->can('import');
The first two snippet imports the symbols if the module uses Exporter or similar. However, instead of importing, it be safer to do
$mod = 'My::Module1'; eval "require $mod"; $mod->function();
The last snippet requires that function accept an extra initial argument.
|
|---|