in reply to Dynamicaly loading modules

You could always eval() your use() statements.
my $include = shift @ARGV; eval "use $include";
This also gets around the fact that use() is evaluated at compile-time. However, with that said, it would probably be nicer to use require() like so
my $include = shift @ARGV; require $include; import $include;
I believe this does essentially does the same thing as use() but gets around the eval() hack and is more tailored towards dynamically loading modules.
HTH

broquaint

Replies are listed 'Best First'.
Re: Re: Dynamicaly loading modules
by Sinister (Friar) on Feb 13, 2002 at 13:19 UTC
    Thanks a lot tilly and broquaint...

    I have been staring at this problem (and many others more for this project) for so long, that I forgot to look at the obvious...

    I do feel a little blond now (no offense there! ;-)

    Sinister greetings.
    "With tying hashes you can do everything God and Larry have forbidden" -- Johan Vromans - YAPC::Europe 2001
    perldoc -q $_

      Hmz,
      both tricks work perfectly, and I now use the Evil eval hack (I didn't sell my soul without side-effects ;-)

      I only wonder though, I use mod_perl for this little bugger, and the following questions raised:

      • Will the modules be sucked into cache (good thing)
      • How can I detect what is in cache? (better thing, even!)

      If you have answers, fellow monks, don't hesitate to shout it out...

      Sinister greetings.
      "With tying hashes you can do everything God and Larry have forbidden" -- Johan Vromans - YAPC::Europe 2001
      `perl -e print; perldoc -q $_
        What do you mean by "cache"? Any code compiled by the perl interpreter will stay there until the process is shut down.

        So, if your reason for only loading the particular module you intend to use was to save memory, it will probably not help much in mod_perl since all of the modules will eventually get loaded into every process.