Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Using Modules in a local directory

by Speedfreak (Sexton)
on Jul 10, 2001 at 16:24 UTC ( [id://95282]=perlquestion: print w/replies, xml ) Need Help??

Speedfreak has asked for the wisdom of the Perl Monks concerning the following question:

Hej all

I've had several discussion to this affect for a while and decided to post it here as I think maybe many people want to know how to do this.

At the moment I'm lucky enough to have my own Linux box on a 2Mb line so I can install what I want when I want on the server.

However, a friend of mine is not so lucky - he rents webspace from a company and has little control outside of his home dir.

He's often wanted to use some of my scripts on his site but as I often use modules from CPAN that arent on his server, we were wondering how to go about using them from within his space when he cant install them into the standard Perl lib tree.

The questions we have are:

1) How can we tell Perl to look for a .pm perl module in a local folder rather than trying to look for it in perl/lib?

2) Say we download a module from CPAN, is it possible to tell "perl Makefile.pl" to install the module locally rather than try and put it in the main lib structure?

-Jed

Replies are listed 'Best First'.
Re: Using Modules in a local directory
by japhy (Canon) on Jul 10, 2001 at 16:29 UTC
    1. use lib "path/to/modules";
    2. perl Makefile.PL PREFIX=/my/dir/modules
    For more, read perlfaq8, "How do I keep my own module/library directory?"

    japhy -- Perl and Regex Hacker
Re: Using Modules in a local directory
by davorg (Chancellor) on Jul 10, 2001 at 16:30 UTC
    1. Perl will look in the current directory for modules that it hasn't found elsewhere. If you look at the values in @INC, you'll see that '.' is the last element.
    2. You can install modules in non-standard locations by using the PREFIX option to Makefile.PL. For example, when installing modules on a machine where I don't have root permissions, I will use a command like:
      perl Makefile.PL PREFIX=~/perl
      which puts the modules in ~/perl/lib/site_perl/5.005. Of course, I then have to set PERL5LIB to include this directory.

    See perlmodinstall for more details.

    --
    <http://www.dave.org.uk>

    Perl Training in the UK <http://www.iterative-software.com>

Re: Using Modules in a local directory
by jeroenes (Priest) on Jul 10, 2001 at 16:41 UTC
    Hi Speedfreak,

    If you put a perl module in the directory you call perl from, let's say /home/jeroenes/work as in:

    cd /home/jeroenes/work perl /var/scripts/script1.pl mylocalfile.txt
    Than perl searches the current/calling dir: /home/jeroenes/work for .pm modules. The use Blah::Foo; statement is seen as "look for Foo.pm in ./Blah/". So use Blah::Foo; will fetch /home/jeroenes/work/Blah/Foo.pm for you.

    As for your second question, see the docs of ExtUtils::MakeMaker. In short, add a LIB directive to the commandline: perl Makefile.pm LIB=/home/jeroenes/work"

    Hope this helps,

    Jeroen
    "We are not alone"(FZ)

Re: Using Modules in a local directory
by mattr (Curate) on Jul 10, 2001 at 17:11 UTC
    You can also include a folder by adding -Ipath/to/folder at the end of the first line of your perl program (which starts with the shebang) after a blank space. But use lib is cooler.

    It is possible that this may work if you make but don't make install.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://95282]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-03-28 21:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found