my $file = $mod; $file =~ s{::}{/}g; $file .= '.pm'; eval { require $file; }; die("Unable to load $mod: $@\n") if $@;
should do what you want.
Note that it executes at run-time (while use executes at compile-time), but that's probably fine. Wrap the code in a BEGIN { } block if you need to execute this at compile-time.
Note that it doesn't import symbols, but that's probably a good thing for dynamically loaded modules. Add $mod->import if $mod->can('import'); if you need to import symbols.
Update: PodMaster suggested that I provide these links: use, require.
In reply to Re: "use" dynamic module
by ikegami
in thread "use" dynamic module
by rsennat
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |