Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Changing @INC path detail

by tytower (Novice)
on Dec 05, 2007 at 20:31 UTC ( [id://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 ?

Replies are listed 'Best First'.
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 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).

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 )=-

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-25 17:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found