in reply to use/require $MODULE (a variable)
You can most definately use a variable - however, Perl will require that you append a file extension if you do.
$foo = "CGI"; require $foo; #this will bork $foo = "CGI.pm"; require $foo; #this won't
You just need to make sure that the variable is visible and assigned an appropriate value when used. To do this, wrap the BEGIN block around the sub AND around the sub - other wise Perl won't see the declaration or the use.
Cheers,BEGIN { sub which_finds_modules { #stuff goes here } @modules = which_finds_modules; foreach $mod(@modules) { require $mod; #make sure it has the extension! } }
|
|---|