LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Using uninstalled Modules (https://www.linuxquestions.org/questions/programming-9/using-uninstalled-modules-333154/)

rigel_kent 06-13-2005 01:25 PM

Using uninstalled Modules
 
Hi there,

This is a question I have for some time, but I can't find the answer. How do we use a Module ( or a package with several ones ) written in Perl, but without installing it in the library of the server ( the hosts, generally, don't install them... )?

With small ones, they just function right - but with others no.

Does anyone knows a solution to this?

Kind regards,

Rigel_Kent

rjlee 06-14-2005 11:53 AM

You can't use a module without making the code accessible to Perl in some way. So this all depends on what you mean by “install”.

If your Perl module has a modulename.pm file, then you can include it with:
Code:

use modulename;
This will search for modulename.pm on every directory listed in @INC, in turn.

So all you need to do to install a module is add the path to the module to @INC:
Code:

BEGIN {
 unshift @INC, "/path/to/module/";
};
use modulename;

You need to put the code to modify @INC in a BEGIN block in order for it to be changed before the use statement.

If your module name contains :: then the .pm file lives in a sub-directory; you need to put the parent of the sub-directory into @INC. (e.g. if your module is named Test::Module and is in /home/testuser/perl/test/module.pm then you would want to add "/home/testuser/perl/" to @INC).

You can also modify the search path on the command-line rather than in a BEGIN block:
Code:

perl -I'/path/to/module/' …

rigel_kent 06-14-2005 12:26 PM

Yep...
 
Hi,

Thanks for the reply. I'll try it - and I believe it will work. I'll let you know.

Thanks again,

Rigel_Kent


All times are GMT -5. The time now is 04:38 PM.