Is it possible to load a module at runtime in Perl? I tried the following, but it didn't work. I wrote the following somewhere in the program:
require some_module;
import some_module ("some_func");
some_func;
Is it possible to load a module at runtime in Perl? I tried the following, but it didn't work. I wrote the following somewhere in the program:
require some_module;
import some_module ("some_func");
some_func;
Look at this "How to dynamically load modules" and you can also look at [DynaLoader - Automatic Dynamic Loading of Perl Modules] in Programming Perl.
# In Foo.pm.
package Foo;
use strict;
use warnings;
use base qw(Exporter);
our @EXPORT = qw(bar);
sub bar { print "bar(@_)\n" }
1;
# In your script.
use strict;
use warnings;
require Foo;
Foo->import('bar');
bar(1, 22, 333);
The easiest way is probably to use a module like Module::Load:
use Module::Load;
load Data::Dumper;