Octavian Rasnita wrote:
Does anyone know how can I do something like:

my $mod = "Module.pm";

#Then require this $mod module (using eval()

#Then executing a certain subroutine from that module and getting
the results.

I found that I can require a module and execute it entirely but I
am not able to choose to execute just a subroutine from it, nor to
extract the value of a certain variable because if I require that
module using eval(), the vars are not exported.

If the module exports something, it will be imported if you import it. ;-) Otherwise you are still able to access subroutines and global variables by calling them with fully qualified names:


    Module::somefunction();

To import something, you can for instance do:

    my $mod = 'Module';   # without the '.pm' extension
    eval "require $mod";
    unless ($@) {
        import $mod qw(somefunction);
        somefunction();
    }

or

    my $mod = 'Module';
    eval "use $mod qw(somefunction)";
    unless ($@) {
        somefunction();
    }

Please see:

    perldoc perlmod
    perldoc -f eval

HTH

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

--
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