athar-qadri has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: @INC
by grinder (Bishop) on Jun 19, 2001 at 12:11 UTC

    It is located somewhere in the binary executable of your Perl interpreter, the exact offset of which tends to change from version to version. But I don't think you really want to know about that. I think what you really want to know is what directories does @INC point to? The following script will print it them out for you:

    #! /usr/bin/perl -w use strict; foreach( @INC ) { print "$_\n"; }
    If you want to include a module from code run anywhere, you have to arrange for it to be stored in one of these directories. Assuming one of the directories in @INC is c:\perl\lib\site_lib, if you wrote a module named Foo/Bar.pm, you would store it in c:\perl\lib\site_lib\Foo\Bar.pm.

    Note that if you run the perl interpreter without doing anything special, the current directory (.) will be included in @INC. Should you run perl with taint checks enabled (via -T), then this will not be the case.

    If you want to add your own directory to the @INC array, the preferred way of doing it is:

    use libs 'c:/personal/code';

    Use forward slashes rather than backslashes in Win32 path names. Perl understands both, but you'll avoid hairy escaping problems. use lib will push your added directory to the beginning of the list, which gives you a handy way of writing your own versions of modules to replace existing library code.

    ~
    --
    g r i n d e r
Re: Location of @INC in win2000
by Zaxo (Archbishop) on Jun 19, 2001 at 11:16 UTC
    @INC is a run-time array. It contains the file system locations to search for modules and libraries. Do this to find its contents:

    $ perl -e 'print(join $/, @INC),$/'

    After Compline,
    Zaxo

(tye)Re: Location of @INC in win2000
by tye (Sage) on Jun 19, 2001 at 18:29 UTC

    Most versions of Perl have a list of directories compiled into the executable. This list is determined at configuration time. Win32 Perl used to have this but also added to this list at run time. Recent versions of Win32 Perl only compute the directories to list in @INC at run time.

    Win32 Perl asks the operating system for the full path name of the its executable. It then strips off the file name (probably "perl.exe"). Then it strips of "/bin/" (and perhaps a directory name containing version information, depending on how that copy of Perl was configured when it was compiled). That gives it the base directory. Then it puts into @INC several copies of that base directory path with different subdirectories appended to it. For example, common versions of Perl for Win32 append "lib" and "site/lib" (but you could also have version-specific and/or platform-specific library subdirectories separate from those, again, depending on how that copy of perl was configured when it was compiled).

    Next, some versions of Perl will look for a value in the Win32 Registry for a list of additional directories to stuff into @INC. Also, "." is put into @INC as the last entry.

    Finally, all of the standard tricks kick in to add even more directories to @INC:

    • $ENV{PERLLIB}
    • $ENV{PERL5LIB}
    • -I on the perl command line
    • use lib
    • etc.

    Note that you probably would have gotten a good answer to this question a lot sooner if you hadn't asked for a reply "asap". We are all volunteers here and do this mostly for the enjoyment of it so, whether you say "kindly" or not, asking for something "asap" just takes some of the fun out of it for many people and so reduces the odds of you getting a good answer quickly. If this seems unfair to you, I kindly offer a full refund of the purchase price. (:

            - tye (but my friends call me "Tye")
Re: Location of @INC in win2000
by frag (Hermit) on Jun 19, 2001 at 23:13 UTC
    If you're trying to identify the values of @INC, just enter perl -V (capital V there) at a prompt, and it'll be there at the very end of the output.

    -- Frag.