Geekuprising.com Logo
Home Youth Debate About Us Clients Services Technologies Code
You are here:: Code > Perl > How can I use perl modules when I can't install them?
spacer
Browse

How do I use perl modules when I can't install them?

Simple Version:

Most perl modules are "pure perl," meaning they are simply text files that can be copied and installed into your local user folders and used in your scripts normally.

You can upload pure perl modules and then use lib '/path/to/where/I/put/modules' to use them in a script.

For scripts that use non-standard modules, you can create a local "modules" directory for your script on your development system, install/copy your modules there and put the whole thing on your server. This is easier than it sounds, too.

A sample directory structure for a number of my scripts might look like:

/home/dan/www/
/home/dan/www/cgi-bin/
/home/dan/www/graphics
/home/dan/modules/
/home/dan/data/
/home/dan/temp/
/home/dan/cron/
Install your modules to the "modules" directory, then all you need to do is change the "use lib" on the remote server to reflect the root there.

Simple Example:

Say you want to use HTML::Template, but don't have root access. You'd create the directory /home/dan/modules/HTML/ and copy the "Template.pm" file there. Then, in your code, you'd put use lib '/home/dan/modules/'; before use HTML::Template; and proceed to use the module normally.

The reason HTML::Template is a "simple" example is because it doesn't have a lot of dependencies needed to provide its core functionality. If you have a module that requires a lot of other modules, I suggest the CPAN method below.

use CPAN

The "best" way to install non-standard modules is to use the CPAN module, which can also follow module dependencies for you. This is a bit tricky, but is described pretty well in item #5, "I am not root, how can I install a module in a personal directory?" of the CPAN faq here.

I HIGHLY suggest you work to figure out how to install modules locally on your target machine via CPAN because it'll make the whole process much easier. If you have access to a C compiler on the target system, you can even install modules with XS components (aka compiled C) via CPAN.

More information:

For more information, see this excellent module installation tutorial and the CPAN documentation.

Discuss this Article!

Copyright 2004 © Geekuprising Internet Consultants