Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

@INC package location

by malaga (Pilgrim)
on May 27, 2002 at 06:54 UTC ( [id://169504]=perlquestion: print w/replies, xml ) Need Help??

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

Is there a place besides @INC where a package can be uploaded and accessed? (no access to @INC) Thanks.

Replies are listed 'Best First'.
Re: @INC package location
by Zaxo (Archbishop) on May 27, 2002 at 07:08 UTC
    use lib '/home/me/lib';

    That changes @INC to include a place you can write to. The environment variable PERL5LIB is also helpful.

    After Compline,
    Zaxo

Re: @INC package location
by baphomet (Pilgrim) on May 27, 2002 at 07:13 UTC

    You can change the contents of @INC on a per-program basis in a couple of ways. Either:

    use lib qw( /some/dir );

    or, something like:

    BEGIN { push @INC, "/some/dir"; }

    Of course, @INC will likely contain the directory from which your program was started. Thus, you should be able to use/require modules that reside in the same directory as your script.

    baphomet.
Re: @INC package location
by strat (Canon) on May 27, 2002 at 11:47 UTC
    To combine scripts and (self-written) modules in relative directories, I like to do something like the following:
    BEGIN { use FindBin qw($Bin); # get actual path of this script use lib "$Bin/../lib"; # add path/../lib/ to @INC use ModuleXY; # load module ModuleXY.pm from lib } # BEGIN
    e.g. if a script is in .../myScript/bin/ and the modules are in .../myScript/lib/

    I use it a lot unter Win2k, Linux and Solaris, and it works great.

    Best regards,
    perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8.8.8.32.11.32"

Re: @INC package location
by malaga (Pilgrim) on May 27, 2002 at 09:41 UTC
    I wouldn't think that, but I wasn't sure what was meant by this:

    "Of course, @INC will likely contain the directory from which your program was started. Thus, you should be able to use/require modules that reside in the same directory as your script."

    So I asked.

    Thanks for the help.
      Normally @INC contains '.' (i.e. current directory). So usually Perl programs can access perl modules in directory from which they were started.

      For example output of perl -V on my computer:

      bash-2.05a$ perl -V Summary of my perl5 (revision 5.0 version 6 subversion 1) configuratio +n: ..... ..... ..... Characteristics of this binary (from libperl): Compile-time options: USE_LARGE_FILES Built under linux Compiled at Jan 11 2002 04:09:18 @INC: /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 . ^^^ - note this dot

      --
      Ilya Martynov (http://martynov.org/)

Re: @INC package location
by malaga (Pilgrim) on May 27, 2002 at 07:19 UTC
    So if I use use lib I lose access to @INC? Is it one or the other? Thanks.
      Why would you think that?

      It's not a secret, perldoc lib

      NAME lib - manipulate @INC at compile time SYNOPSIS use lib LIST; no lib LIST; DESCRIPTION This is a small simple module which simplifies the manipulation of + @INC at compile time. It is typically used to add extra directories to perl's search pat +h so that later "use" or "require" statements will find modules which a +re not located on perl's default search path. Adding directories to @INC The parameters to "use lib" are added to the start of the perl sea +rch path. Saying use lib LIST; is *almost* the same as saying BEGIN { unshift(@INC, LIST) } For each directory in LIST (called $dir here) the lib module also +checks to see if a directory called $dir/$archname/auto exists. If so the $dir/$archname directory is assumed to be a corresponding architec +ture specific directory and is added to @INC in front of $dir. To avoid memory leaks, all trailing duplicate entries in @INC are removed. Deleting directories from @INC You should normally only add directories to @INC. If you need to d +elete directories from @INC take care to only delete those which you add +ed yourself or which you are certain are not needed by other modules +in your script. Other modules may have added directories which they n +eed for correct operation. The "no lib" statement deletes all instances of each named directo +ry from @INC. For each directory in LIST (called $dir here) the lib module also +checks to see if a directory called $dir/$archname/auto exists. If so the $dir/$archname directory is assumed to be a corresponding architec +ture specific directory and is also deleted from @INC. Restoring original @INC When the lib module is first loaded it records the current value o +f @INC in an array "@lib::ORIG_INC". To restore @INC to that value you ca +n say @INC = @lib::ORIG_INC; SEE ALSO FindBin - optional module which deals with paths relative to the s +ource file. AUTHOR Tim Bunce, 2nd June 1995.
      perlfaq-q INC
      How do I add a directory to my include path at runtime? Here are the suggested ways of modifying your include path +: the PERLLIB environment variable the PERL5LIB environment variable the perl -Idir command line flag the use lib pragma, as in use lib "$ENV{HOME}/myown_perllib"; The latter is particularly useful because it knows about m +achine dependent architectures. The lib.pm pragmatic module was f +irst included with the 5.002 release of Perl.
      How To Read The Friendly Manual which has at least 90% of all the answers

       
      ______crazyinsomniac_____________________________
      Of all the things I've lost, I miss my mind the most.
      perl -e "$q=$_;map({chr unpack qq;H*;,$_}split(q;;,q*H*));print;$q/$q;"

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://169504]
Approved by virtualsue
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2024-04-23 08:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found