Home > Archive > PERL CGI Beginners > May 2004 > Running a Perl module
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Running a Perl module
|
|
| Octavian Rasnita 2004-05-22, 11:31 am |
| 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";
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.
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?
Thank you very much.
Teddy
| |
| Bob Showalter 2004-05-22, 11:31 am |
| 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.
| |
| Octavian Rasnita 2004-05-22, 11:31 am |
| Hi,
Ok, I see. Please tell me if there is a way to do what I want.
I want to get a certain string value from a text file, use that text string
as the name for a module, execute that module, and get the result of a
certain variable which is created in that module for using it in the program
which calls the module.
It is not absolutely necessary to use a .pm module, but I want to choose
what perl file I want to execute and get its result in the program that
calls it.
I would like not to be forced to use the shell, and i hope it is possible.
Thank you.
Teddy
----- Original Message -----
From: "Bob Showalter" <Bob_Showalter@taylorwhite.com>
To: "'Octavian Rasnita'" <orasnita@fcc.ro>; <beginners-cgi@perl.org>
Sent: Monday, April 05, 2004 3:29 PM
Subject: RE: Running a Perl module
[color=darkred]
> Octavian Rasnita wrote:
|
|
|
|
|