On Thursday 20 December 2007 10:38, Octavian Rasnita wrote:
>
> Hello,

Hello,

> I have a directory named "Questionnaire" which contains some modules
> like "Files.pm", "MySQL.pm", and maybe others...
>
> and I want to be able to choose the wanted module at runtime, using a
> code like:
>
> my $module = "Files";
>
> require Questionnaire::$module;
> my $obj = Questionnaire::$module->new();
>
> and of course, if I would offer another value for $module, like
> "MySQL", the program should use Questionnaire::MySQL instead.
>
> First please tell me if this is a good practice, or I should better
> use
>
> if ($module eq "Files") {
> require Questionnaire::Files;
> $obj = Questionnaire::Files->new();
> }
> elsif (...) {
> ...
> }
>
> Then please tell me how to do this... if it is possible.

Look up the "Autoloading" section of perlsub:

perldoc perlsub

Also:

perldoc AutoLoader



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to