Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Using arbitrary packages

by ysth (Canon)
on Jul 12, 2004 at 21:52 UTC ( [id://373747]=note: print w/replies, xml ) Need Help??


in reply to Using arbitrary packages

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.

Replies are listed 'Best First'.
Re^2: Using arbitrary packages
by Sprad (Hermit) on Jul 12, 2004 at 22:14 UTC
    In a nutshell, I'd like to have a config file that contains module names and function names. I want to read the config file, 'use' all the modules, and then make the function calls as given in the config file.

    It's all trusted data, since it's all being run locally.

    ---
    A fair fight is a sign of poor planning.

      Perhaps you should use
      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.
Re^2: Using arbitrary packages
by PodMaster (Abbot) on Jul 13, 2004 at 05:16 UTC
    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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://373747]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (2)
As of 2025-06-20 04:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.