Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

How is the default @INC constructed?

by johnnywang (Priest)
on Aug 24, 2004 at 18:28 UTC ( [id://385469]=perlquestion: print w/replies, xml ) Need Help??

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

Hi, I know how to change @INC:
  1. use lib
  2. Environment variable: PERL5LIB, PERLLIB
  3. directly manipulate @INC
  4. -I
But how is the default @INC constructed? how do I change that without using any of the above approach, especially 1, 3 which requires change code? Is it part of a distribution for a platform? Thanks.

Replies are listed 'Best First'.
Re: How is the default @INC constructed?
by Aristotle (Chancellor) on Aug 24, 2004 at 18:44 UTC

    You can set the directories to be added to @INC by default when you compile Perl. Or more precisely: when you run Configure, before compiling.

    So yes, the default is usually part of the binary distribution for a platform.

    Makeshifts last the longest.

Re: How is the default @INC constructed?
by PodMaster (Abbot) on Aug 25, 2004 at 05:55 UTC
    Besides paths being compiled in, on win32 at least, the @INC values are determined dynamically, and the directory name where perl is located can make a difference, observe:
    C:\dev\perls>dir 5.6.2 Volume in drive C has no label. Volume Serial Number is 44B0-3C2E Directory of C:\dev\perls\5.6.2 07/27/2004 06:30 AM <DIR> . 07/27/2004 06:30 AM <DIR> .. 07/27/2004 07:31 AM <DIR> bin 07/27/2004 06:30 AM <DIR> html 07/27/2004 06:50 AM <DIR> lib 07/27/2004 06:29 AM <DIR> site 0 File(s) 0 bytes 6 Dir(s) 34,454,638,592 bytes free C:\dev\perls>5.6.2\bin\perl -le"print for @INC" C:/dev/perls/5.6.2/lib . C:\dev\perls>rename 5.6.2 v5.6.2 C:\dev\perls>v5.6.2\bin\perl -le"print for @INC" C:/dev/perls/v5.6.2/lib C:/dev/perls/v5.6.2/site/lib . C:\dev\perls> C:\dev\perls>rename v5.6.2 5.6.2f C:\dev\perls>5.6.2f\bin\perl -le"print for @INC" C:/dev/perls/5.6.2f/lib . C:\dev\perls>rename 5.6.2f f C:\dev\perls>f\bin\perl -le"print for @INC" C:/dev/perls/f/lib C:/dev/perls/f/site/lib . C:\dev\perls>f\bin\perl -V Summary of my perl5 (revision 5 version 6 subversion 2) configuration: Platform: osname=MSWin32, osvers=4.0, archname=MSWin32-x86-multi-thread uname='' config_args='undef' hint=recommended, useposix=true, d_sigaction=undef usethreads=undef use5005threads=undef useithreads=define usemultip +licity=define useperlio=undef d_sfio=undef uselargefiles=undef usesocks=undef use64bitint=undef use64bitall=undef uselongdouble=undef Compiler: cc='cl', ccflags ='-nologo -O1 -MD -DNDEBUG -DWIN32 -D_CONSOLE -DN +O_STRICT -DHAVE_DES_FCRYPT -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DPERL_MSVCRT_READFIX', optimize='-O1 -MD -DNDEBUG', cppflags='-DWIN32' ccversion='', gccversion='', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234 d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', + lseeksize=4 alignbytes=8, usemymalloc=n, prototype=define Linker and Libraries: ld='link', ldflags ='-nologo -nodefaultlib -release -libpath:"c:\ +dev\perls\f\lib\CORE" -machine:x86' libpth=C:\PROGRA~1\MIAF9D~1\VC98\lib libs= oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib + comdlg32.lib advapi32.lib shell32.lib ole32.lib ol eaut32.lib netapi32.lib uuid.lib wsock32.lib mpr.lib winmm.lib versi +on.lib odbc32.lib odbccp32.lib msvcrt.lib perllibs= oldnames.lib kernel32.lib user32.lib gdi32.lib winspool +.lib comdlg32.lib advapi32.lib shell32.lib b oleaut32.lib netapi32.lib uuid.lib wsock32.lib mpr.lib winmm.lib v +ersion.lib odbc32.lib odbccp32.lib msvcrt.lib libc=msvcrt.lib, so=dll, useshrplib=yes, libperl=perl56.lib Dynamic Linking: dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' ' cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -release -l +ibpath:"c:\dev\perls\f\lib\CORE" -machine:x86' Characteristics of this binary (from libperl): Compile-time options: MULTIPLICITY USE_ITHREADS PERL_IMPLICIT_CONTEX +T PERL_IMPLICIT_SYS Built under MSWin32 Compiled at Jul 27 2004 07:58:39 @INC: C:/dev/perls/f/lib C:/dev/perls/f/site/lib .

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

Re: How is the default @INC constructed?
by Velaki (Chaplain) on Aug 24, 2004 at 19:17 UTC

    During the configuration process in preparation to build a new release of perl on your system, there are a number of questions and settings that refer to the location of libraries. Essentially, these paths are "Compiled In"; however, you can always change the default during the build.

    A nifty build trick is to add library paths to be added to the front of the @INC path, thus overriding the built-ins with your own modules, should you choose to do so.

    The relevant portion of code is

    sh Configure -Accflags='-DAPPLLIB_EXP=\"/other/lib/dir\"'
    as per the CPAN Install - Build and Installation guide for perl5 page.

    "Perl. There is no substitute."
Re: How is the default @INC constructed?
by eyepopslikeamosquito (Archbishop) on Aug 25, 2004 at 05:20 UTC

    Improving the perl build system to allow relocation without requiring recompilation is certainly do-able and is on the P5P wish list. One way to implement this is to build all executables with dummy and very long paths stuffed into the executable, then write a utility to binary edit them when you move them. Sounds hacky, but in practice it works well and is better than the alternatives.

    ActiveState's reloc_perl utility is an example of one way to do it.

Re: How is the default @INC constructed?
by ikegami (Patriarch) on Aug 24, 2004 at 18:42 UTC
    I imagine it's built from a constant in is created when perl is built based on compiler flags and whatnot. (And in turn, is used to extract options needed to compile modules.)
      Not quite. How would it find without knowing the @INC?

      The answer, as others have said, is that @INC is built in to the Perl binary, so you can't change it without recompiling the binary.

      -- Randal L. Schwartz, Perl hacker
      Be sure to read my standard disclaimer if this is a reply.

        *sigh* Too true. I must have bonked myself on the head too many times.

        Are some generated instead of being hardcoded? I orignally installed my ActiveState perl in R:\U, but recently moved it to R:\Utils (without reinstalling), and I get:

        >perl -le "$,=', '; print @INC" r:/Utils/perl/lib, r:/Utils/perl/site/lib, .

        I did have to edit for PPM to work in the new directory.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://385469]
Approved by Limbic~Region
Front-paged by broquaint
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (6)
As of 2024-07-22 11:19 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.