eval "use $foo";
die $@ if $@ # die with error message if it failed
will do it but it will do it at runtime, whereas a genuine use will do it at compile time. If you do
BEGIN
{
my $foo = get_a_module_name();
eval "use $foo";
die $@ if $@
}
it will happen at compile time, you just need to be careful that $foo has a value at compile time.
| [reply] [Watch: Dir/Any] [d/l] [select] |
If $foo is trusted data, you can say eval "use $foo";, but that won't take effect at compile time.
Starting with 5.6.2, you can say use if 1, $foo;
but $foo has to already be set at compile time, e.g.
my $foo;
BEGIN { $foo = $ENV{SERIALIZER} || "Storable" }
use if 1, $foo;
but even that IMO is more clearly written as
BEGIN { eval "use ".($ENV{SERIALIZER}||"Storable"); }
What exactly are you trying to accomplish? There's probably a better way. | [reply] [Watch: Dir/Any] [d/l] [select] |
| [reply] [Watch: Dir/Any] |
do $filename;
and have actual real Perl in the file that looks like
use Module1;
use Module2;
function1();
function2();
it will run faster. No point in inventing your own mini perl parser. Especially if in the future you decide you need to start adding arguments to your functions etc.
| [reply] [Watch: Dir/Any] [d/l] [select] |
Starting with 5.6.2, you can say
Its more like starting with perl 5 (if its on CPAN, you can get it from CPAN) :D
MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!" | I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README). | ** The third rule of perl club is a statement of fact: pod is sexy. |
| [reply] [Watch: Dir/Any] |