How do I load a module at runtime in Perl?

module, perl

Solution

Foo.pm

package Foo;

use strict;
use warnings;

use Exporter qw(import);
our @EXPORT = qw(bar);

sub bar { print "bar(@_)\n" }

1;

script.pl

use strict;
use warnings;

require Foo;
Foo->import('bar');
bar(1, 22, 333);

Problem

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; ```

Original source