crenz has asked for the wisdom of the Perl Monks concerning the following question:
Fellow monks,
for some module, I need to include other modules based on run-time information. Here's roughly what I am doing right now:
sub init { my ($someModule, $someCondition) = @_; eval "use Acme::$someModule"; eval "use Funky::Library" if $someCondition; } init("Bleach", 1);
Now, for some reason, I don't really like eval "$some $code". I fear the performance hit (although I have no idea whether there really is one), and more importantly I just don't like the thought of compiling during runtime. I guess I could rewrite the code using require and import, like this:
sub init { my ($someModule, $someCondition) = @_; require "Acme/$someModule.pm"; import "Acme/$someModule.pm"; if $someCondition { require Funky::Library; import Funky::Library qw(grooves moves); } } init("Bleach", 1);
Is this the canonical way to solve that problem; are there any issues I need to be aware of?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: run-time module usage
by Courage (Parson) on Aug 02, 2002 at 19:54 UTC | |
|
Re: run-time module usage
by Zaxo (Archbishop) on Aug 02, 2002 at 21:25 UTC | |
|
Re: run-time module usage
by crenz (Priest) on Aug 02, 2002 at 21:11 UTC |