On Dec 20, 6:38 pm, [EMAIL PROTECTED] (Octavian Rasnita) wrote:

> 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();

eval "require Questionnaire::$module; 1" or die $@;
my $obj = "Questionnaire::$module"->new();

See also UNIVERSAL::require

> 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();}

That is a bit of a religious issue.


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


Reply via email to