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

Simple Question: how can I change/add to/modify my @INC paths?

Replies are listed 'Best First'.
(jeffa) Re: @INC
by jeffa (Bishop) on Jul 26, 2001 at 02:36 UTC
    Since @INC is just an array, you can push new directories to it:
    push @INC, '/my/new/path';
    But if you are getting at what i _think_ are you, i recommend using this instead:
    use lib '/my/lib/stuff';

    Jeff

    R-R-R--R-R-R--R-R-R--R-R-R--R-R-R--
    L-L--L-L--L-L--L-L--L-L--L-L--L-L--
    
      Hmmm. I think I may be operating under a false assumption. I was under the impretion that the @INC paths are a global variable. I want to alter that variable, that way I won't have to change ALL of the scripts.
        If you want to avoid changing a bunch of scripts, you can
        setenv PERL5LIB /some/other/directory
        ... or however you do it with your particular shell.
        @INC is global to the script you are using - one script. You will have to edit each of the scripts you are refering (sic) to . . . sounds like a job for . . . Perl!
        script to edit multiple files and add said line left as exercise to the reader >:)

        Jeff

        R-R-R--R-R-R--R-R-R--R-R-R--R-R-R--
        L-L--L-L--L-L--L-L--L-L--L-L--L-L--
        

      I've wondered about this myself.

      Why would it be better to use lib '/foo/bar' than to push @INC,'/foo/bar/';?

        You did want your change to be seen while Perl is still compiling the script?
Re: @INC
by Cubes (Pilgrim) on Jul 26, 2001 at 02:38 UTC
    use lib

    Update: This is better than simply adding to @INC for a couple of pretty obscure reasons that I had to look up: use lib does some magic with architecture specific directories, and it saves off the original @INC for you in case you need it later.

      Most people will notice a less obscure benefit. lib does its thing at compile time, which means that the change to @INC happens before other modules load. Otherwise you need to use a BEGIN block.