Octavian Rasnita wrote:
> Hi all
>
> I want to run a certain perl module by getting the name of the perl
> module from a scalar variable like:
>
> $module ="Test";
> require $module;
>
> I have read in the POD documentation that I need to use:
>
> eval {require $module};
> or
> eval "require $module";

You need to use the latter. The former won't do what you want. And you need
to check for errors.

>
> But the problem is that I cannot get a value returned by that module.
>
> The Test module returns a value named $value.
>
> If I use:
>
> require Test;
> print $value;
>
> The var $value is printed without problems, but if I call require for
> the $module, the var $value is not exported and I cannot use it.

require() does not do exporting, so I'm not sure what you're saying here.

The following are equivalent:

   require MyModule;

   $mod = "MyModule";
   eval "require $mod";

>
> Is Perl able to run a certain module if getting the name of the
> module from a variable, and able to access a value returned by that
> module?

Not sure what you mean by "returned by that module". Modules are required to
return a true value to indicate that they were successfully initialized. If
you want that specific value, just assign the results of the require() or
eval.

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


Reply via email to