in reply to Use with variable
$mod = "Digest::MD5"; eval "require $mod"; [download]
If you're already going to eval, might as well just do:
my $mod = "Digest::MD5"; eval "use $mod"; [download]
and avoid calling import yourself...
And don't forget to check $@...
Actually, you don't need to interpolate the variable, and it's much safer not to:
my $module = "Digest::MD5"; eval 'use $module'; # note single quotes [download]
That's because use $var actually works. You just have to somehow populate $var before the compile-time effect of use takes place. A BEGIN block lets you do that. Silly example:
my $module; BEGIN { $module = "Digest::MD5"; } use $module; [download]
Note that the snippets of course aren't equivalent — the first loads the module at runtime, the second loads it at compile time.
Makeshifts last the longest.