Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

adding custom libraries to my perl

by asinghvi (Acolyte)
on Oct 17, 2001 at 20:14 UTC ( #119448=perlquestion: print w/replies, xml ) Need Help??

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

PerlMonks
Need basic info
How do I add my own library paths (where I store my own packages etc)
to @INC so that I do have to say
. use lib "path" in every perl script that I write.
This is critical when I am not root on a UNix server and I want to install modules.

Replies are listed 'Best First'.
Re: adding custom libraries to my perl
by tune (Curate) on Oct 17, 2001 at 20:22 UTC
    Set the PERL5LIB variable in your profile.
    E.g.
    export PERL5LIB = "/home/asinghvi/perl/mymodules/"

    --
    tune

Re: adding custom libraries to my perl
by echo (Pilgrim) on Oct 17, 2001 at 20:23 UTC
    Set the environment PERL5LIB to your modules' path (or paths). You can do this in your shell startup file for example. You might also need to do it in your crontab.
Re: adding custom libraries to my perl
by {NULE} (Hermit) on Oct 18, 2001 at 15:48 UTC
    Hi,

    I reply to this at my own peril, I realize, but I thought I'd mention 'Another Way To Do It'.

    On a per script basis you can alter the @INC with:
    BEGIN{unshift @INC, "/path/to/stuff"}

    For the vast majority of things you do it is easier and better to follow the suggestions of the other monks here.

    Also for installing modules in odd places I usually do a get Module::Whatever from within the CPAN shell, but then exit and go to ~/.cpan/build/Module-Whatever-0.01a and manually from there do a perl Makefile.pm Once that process is complete you can edit the Makefile that has been generated and change PREFIX= to read the path where you want it installed. From there it's usually just make, make test and make install.

    There are also configuration settings within the CPAN shell that may help you alter install locations and the like - o conf will show you the options.

    Again, don't do it this way - I merely present a different approach. This is something I find convienent to play with modules I want to have around one day and gone the next, particularly when I'm working on a module in-house.

    Good luck,
    {NULE}
    --
    http://www.nule.org

      If you're going to use this technique, use lib '/path/to/stuff' is easier to read, write and maintain than BEGIN{unshift @INC, "/path/to/stuff"}, although they do exactly the same thing.

      See perlman:lib:lib (perldoc lib) for more details.

Re: adding custom libraries to my perl
by tommyw (Hermit) on Oct 18, 2001 at 17:23 UTC

    The other option, if you can't conveniently get to environment variables (eg, under a web server) is to use the -I flag on the command line:
    From the perlrun page:
    <cite> -Idirectory
      Directories specified by -I are prepended to the search path for modules (@INC)</cite>...

    Of course, then you've got to get the flag to the script, which means either typing it (in which case you can get to the environment), or putting on the end of the #! line which means altering the script, which you want to avoid. But at least it's the first line, so it's easy to mangle with some pre-processor code.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2021-09-20 14:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?