Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Changing @INC path detail

by tytower (Novice)
on Dec 05, 2007 at 20:31 UTC ( #655213=perlquestion: print w/ replies, xml ) Need Help??
tytower has asked for the wisdom of the Perl Monks concerning the following question:

QUESTION - Quote"I install my development perl in /usr/local, so I still have the systems standard perl install in /usr"

How do I get this to be included in the path info in @INC ?

Comment on Changing @INC path detail
Re: Changing @INC path detail
by gamache (Friar) on Dec 05, 2007 at 20:36 UTC
    The preferred way to add directories to @INC is like this:
    use lib qw(/path/to/dir1 /path/to/dir2 ...);

    There's documentation here.

Re: Changing @INC path detail
by dynamo (Chaplain) on Dec 05, 2007 at 20:54 UTC
    use lib is the Right way to do it, but you can also do it the same way you manipulate any other array:
    my $override_lib_path = "/usr/local/Perl/5.8.6/whatever"; my $backup_lib_path = "/lastresort/path/to/lib"; # look in $override_lib_path first unshift @INC, $override_lib_path; # look in $backup_lib_path last if # no match for a module name is found first push @INC, $backup_lib_path;
    Good luck.
      You have to take care that you fold that into a BEGIN block, because use is evaluated at compile time.

      If you have a script like this:

      # modify @INC use Some::Module;
      the use is evaluated before the # modify @ING line.

      You see, it's not as easy at it looks, which is why use lib $path; is recommended. (It checks for duplicate entries in @INC as well, which is another advantage).

Re: Changing @INC path detail
by sh1tn (Priest) on Dec 05, 2007 at 20:57 UTC
    In addition - the pragma itself - lib.


Re: Changing @INC path detail
by graq (Curate) on Dec 06, 2007 at 08:52 UTC

    If you have some code that you want to flip between using different library paths, you can make it $ENV dependent.

    BEGIN { $ENV{$_} && unshift @INC, $ENV{$_} for (qw|DEVA_OR_DEVB|); }

    Setting up $ENV will depend on your OS / server environment.

    -=( Graq )=-

Re: Changing @INC path detail
by bart (Canon) on Dec 06, 2007 at 13:07 UTC
    Alternatively to lib or direct manipulation of @INC, you can provide the -I command line switch... Just -I plus the directory path, as one word or with whitespace between them, and optionally quoted.

    The PERL5OPT environment variable can automatically include it on every script you run (except under -T — taint checks).

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2014-07-28 06:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (189 votes), past polls