Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Help adding paths to @INC

by cstrawfield (Initiate)
on Apr 22, 2012 at 21:21 UTC ( #966497=perlquestion: print w/replies, xml ) Need Help??
cstrawfield has asked for the wisdom of the Perl Monks concerning the following question:

I'd like to add a path to the @INC array to reconcile differences between a new server and our old servers. They're CentOS servers (new is CentOS 6, old are 5.x), and though the monks will scoff, I must admit to generally going with whatever Perl and Apache versions the yum repos were offering -- I'm pretty lame with software management, and yum usually keeps me out of trouble.

Is it possible to add an additional path to @INC without recompiling? Any help much appreciated.

Replies are listed 'Best First'.
Re: Help adding paths to @INC
by tobyink (Abbot) on Apr 22, 2012 at 21:39 UTC

    There are four ways of fiddling with @INC without recompiling Perl:

    1. Set the PERL5LIB environment variable.
    2. Use the "-I" command-line option.
    3. Modify it in your Perl script itself, e.g. by explicitly pushing paths onto @INC in a BEGIN block, or via lib.
    4. In, if your version of Perl has been compiled with support for it.
    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
      Thanks, tobyink. Your suggestion to use lib appeared to be the simplest solution, in the circumstances. Specifically, this:

      use lib '/usr/lib/perl5/site_perl'; # add path to @INC
      More info here

Re: Help adding paths to @INC
by tospo (Hermit) on Apr 23, 2012 at 08:15 UTC
    use lib [...]
    is ok if all your scripts need to use that paths in all your environments, but that doesn't seem to be what you need.
    A better way of controlling include paths that would allow you to manage the different requirements of different servers is to use local::lib. It may seem a bit complicated at first but it really isn't. Just follow the description of "The bootstrapping technique" to set up your local library path in the .bashrc (or csh/tcsh whatever you are using) script in the $HOME dir of each machine.
    What that is doing is to set the PERL5LIB and some other environment variables for you so that a) @INC will include the correct path on each machine and b) modules will automatically be installed into the correct path using cpan(p|m).

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://966497]
Approved by tobyink
Front-paged by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2017-01-21 11:12 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (184 votes). Check out past polls.