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

I've two questions about @INC:

Q1: When I do perl -V, I see some directories in @INC that aren't part of the perl core, but point to directories added here. In what config files should I look to see where these extra dirs are getting added to @INC? (And "perl" isn't aliased with -I flags; which perl returns /usr/bin/perl.)

Q2:  /usr/local/lib/site_perl is listed in @INC. Is this standard? And the presence of /usr/local/lib/site_perl in @INC does NOT mean that  /usr/local/lib/site_perl/lib (which isn't listed in @INC) would be searched, right?

thanks for any tips

water water water

Replies are listed 'Best First'.
Re: perl -V
by eXile (Priest) on Jul 31, 2004 at 17:15 UTC
    Q1: AFAIK there are 2 ways of externally modifying @INC
    • 1. PERL5LIB environment-variable
    • 2. -I<directory-to-library>
    Q2: only the directories in @INC, and not subdirectories are searched for modules. Of course for the module Data::Dumper all directories in @INC would be searched for a subdirectory called 'Data', with a file called Dumper.pm.
      Many thanks.

      Is there a way to ask perl which directories in @INC are "built-ins" (from the build), vs. "user-added" (via -I or PERLLIB or PERL5LIB activity?)

        Use the toolkit.

        env -i perl -V

        Makeshifts last the longest.

Re: perl -V
by hossman (Prior) on Jul 31, 2004 at 23:46 UTC
    1. Different distrobutions compile in different lists of "default" library paths. Usually as a way of making sure that modules you install with CPAN don't overwrite/get overwritten by modules installed using the distrobutions own packaging system.

    2. If a directory is in your @INC because of the $ENV{PERL5LIB}, then it will also show up in the %ENV section just above @INC. I don't believe anything similar happens for directories added using -I

      laptop:~> setenv PERL5LIB /perl5lib/env/var laptop:~> perl -V -I /dash/I | tail -15 Built under linux Compiled at Apr 4 2004 05:57:53 %ENV: PERL5LIB="/perl5lib/env/var" @INC: /dash/I /perl5lib/env/var /usr/local/lib/perl/5.6.1 /usr/local/share/perl/5.6.1 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.6.1 /usr/share/perl/5.6.1 /usr/local/lib/site_perl .
    3. The Config module tells you all sorts of info on how your perl was built...

      laptop:~> perl -l -MConfig -e'while(($k,$v)=each(%Config)) { print "$k +=$v" if $k =~ /lib/i or $v =~ /lib/i }' | head archlibexp=/usr/lib/perl/5.6.1 installarchlib=/usr/lib/perl/5.6.1 installprivlib=/usr/share/perl/5.6.1 libpth=/usr/local/lib /lib /usr/lib libs=-lgdbm -ldb -ldl -lm -lc -lcrypt privlibexp=/usr/share/perl/5.6.1 archlib=/usr/lib/perl/5.6.1 config_arg11=-Dsitelib=/usr/local/share/perl/5.6.1 config_arg12=-Dsitearch=/usr/local/lib/perl/5.6.1 config_arg21=-Duseshrplib
Re: perl -V
by davidj (Priest) on Jul 31, 2004 at 17:22 UTC
    As for Q1: check your PERL5LIB environmental variable (echo $PERL5LIB). (setting PERL5LIB is a way of including directories that are not normally part of @INC. It lets you customize your environment). You might find some of the directories listed there. You might also want to take a look at your start-up scripts. If they inherit other environments, they too may have PERL5LIB set. As for the -I flag. If it is followed by a list of directories, those directories will be added to the front of @INC for the execution of that script only. It is a way of specifying search directories for individual scripts.

    As for Q2: all subdirectories of the directories included in @INC will be searched. In other words, yes, /usr/local/lib/site_perl/lib will be searched.

    davidj

    update: I am wrong about my answer to Q2. eXile is right. Subdirectories will not be searched. Not sure what I was thinking there :)
Re: perl -V
by pbeckingham (Parson) on Jul 31, 2004 at 23:13 UTC

    The ways I know of modifying @INC:

    1. use lib 'path';
    2. push @INC, 'path'
    3. unshift @INC, 'path'
    4. #! /usr/bin/perl -Ipath
    5. $ENV{PERL5LIB}

Re: perl -V
by water (Deacon) on Jul 31, 2004 at 17:35 UTC
    I can't find where in the perl docs is says subdirs of @INC are searched automatically -- looked in perlmod, perlmodlib, and perlmodstyle.

    Are not-explicitly-named subdirs of @INC searched?

    (Of course  use Foo::Bar::Baz; needs to go into Foo/Bar/ to get to Baz, but that to me is explicit. I mean, you can't just say  use Baz; and expect perl to search down to find it, yes?

    So, unable to find docs, and getting confusing test results (likely other errors), logic would indicate subdirs of @INC aren't automatically searched.

    WOuld be delighted for someone authoritative to weigh in, or post a pointer to the docs where this is explained.

    (One reason I am confused is that the code I am looking at -- which itself may not be correct, that's another issue -- seems to rely on the fact that

    /usr/local/lib/site_perl/lib
    is part of @INC, where (I think) only
    /usr/local/lib/site_perl
    is.)

    Confused I am.