Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

setting path to LIB folder

by vvh (Initiate)
on Apr 15, 2004 at 10:36 UTC ( [id://345345]=perlquestion: print w/replies, xml ) Need Help??

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

i have included modules in my perl program. i have stored that program in a different directory. i don't want to copy the *.pm files into my program directory. how should i set the path for lib folder or *.pm folder? plz reply. its urgent

Replies are listed 'Best First'.
Re: setting path to LIB folder
by Corion (Patriarch) on Apr 15, 2004 at 10:42 UTC

    You have many options. Let's assume you put your program specific modules in a directory lib/ below your current program directory.

    The most common option is to use the lib pragma:

    use lib 'lib';

    You can also do yourself what the lib pragma does:

    BEGIN { unshift @INC, 'lib' };

    You can also change the environment variable that Perl looks at for additional include directories:

    # in the shell script that starts your program: PERL5LIB=/home/vvh/program/lib export PERL5LIB perl -w /home/vvh/program/program.pl $*

    Or you can start Perl with the -I parameter to specify the additional include directory:

    # in the shell script that starts your program: perl -w -I/home/vvh/program/lib /home/vvh/program/program.pl $*
Re: setting path to LIB folder
by vagnerr (Prior) on Apr 15, 2004 at 11:07 UTC
    If you have many perl scripts, or don't what to have to do a "use lib" in all your scripts you can also set the environment variable PERL5LIB to the directory containing your modules. eg.
    export PERL5LIB=/path/to/lib/dir
    Under unix (specificaly bash). If you put that in your .bash_profile then you dont have to worry about it again

    _______________________________________________________
    Remember that amateurs built Noah's Ark. Professionals built the Titanic.
      If this is for CGI scripts under Apache, and Taint isn't on, then you can set environment variables in your httpd.conf or .htaccess files, using the SetEnv directive. If your server setup allows it...

      I don't even know which directive-type you'd have to allow, except that it definitely won't work if AllowOverride is set to "None". ("In this case, the server will not even attempt to read .htaccess files in the filesystem.")

      Except when you turn -Taint on
Re: setting path to LIB folder
by Anonymous Monk on Apr 16, 2004 at 06:43 UTC
    Or just move the perl modules into your local site directory, which under debian linux is: /usr/local/lib/site_perl
    To find it on a unixy system, run:
    perl -e 'print "@INC\n"'
    Or on a more braindead platform:
    perl -e "print join(',',@INC)"

    And look for a directory that ends in site_perl. This is what that directory is for, if you have write permissions to it...

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-20 09:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found