in reply to Re: Loading a Module from a Variable
in thread Loading a Module from a Variable

Thanks for the quick reply,

My perl application takes as input a module and dynamically loads it, then calls the necessary functions. I could easily take the input argument (array) and write it to a temporary file, and require it, however I am using Perl...so there must be a way...

I had tried your suggestion, however I ran into some problems since my module is defines something like:
package testmod; use DynaLoader; use Exporter; BEGIN { @ISA = qw(Exporter, DynaLoader); @EXPORT = qw(testfunc); @EXPORT_OK = qw(); } use strict; sub testfunc { ... } 1;
The errors I am getting are "Global symbol @ISA requires explicit package name..."

PS: Thanks for the heads up on $@, I always get those confused.

zi99er

Replies are listed 'Best First'.
Re^3: Loading a Module from a Variable
by nobull (Friar) on Sep 21, 2005 at 16:46 UTC
    eval, unlike require does not evaluate the code in a new top-level lexical scope. Any lexically scoped varaibles or pragmas will be inherited by the code.

    One way to avoid use strict and use warnings being inherited by your evaled source is to simply no strict; no warnings; before you eval.

    To avoid lexical variables, put the eval() in a subroutine that appears before any file scoped lexicals (and before the pragmas too).

    # Start of program sub myeval { eval shift } use strict; use warnings; # ...rest of program

    A completely different approach would be to put a code reference into @INC. That way you can actually use require.