Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

@INC: search sequence of directories

by kdjantzen (Acolyte)
on Apr 25, 2007 at 09:36 UTC ( [id://611947]=perlquestion: print w/replies, xml ) Need Help??

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

Greeting Monks,

after having learned through the answer to my previuos submission how to correctly specify the enviroment variable for a "use lib ..." statement I now found out that indepent of what I specify the directories appear in @INC in a specifc sequence.

In the environment variable I specify:
/home/.../MyTest:/home/.../home/MyModules
because I want use the modifications of certain modules located in MyTest instead of the appropriate unchanged modules in MyModules.

In @INC my directories always are listed as
... MyModules
... MyTest
other directories

My question:
How can I ensure that in @INC my directories are in the sequence that I specified?

Thanks for your help.

Replies are listed 'Best First'.
Re: @INC: search sequence of directories
by shigetsu (Hermit) on Apr 25, 2007 at 09:49 UTC
    Excerpt from lib:

    The parameters to use lib are added to the start of the perl search path. Saying

    use lib LIST;
    is almost the same as saying
    BEGIN { unshift(@INC, LIST) }

    Perhaps

    BEGIN { push(@INC, LIST) }
    does what you want?

Re: @INC: search sequence of directories
by varian (Chaplain) on Apr 25, 2007 at 10:02 UTC
    Whatever you specify in the environment variable (PERL5LIB) is supposed to be prepended to the @INC in the same sequence as per your specification. It works fine on my platform (Perl 5.8.5 on FC Linux).

    What version/platform do your run? Did you export the shell environment variable after an update?

      I am running perl 5.8.6 under Suse Linux 9.3.

      The environment variable is set by a bash script based on an option.
      The bash script, in turn, calls the perl script.

Re: @INC: search sequence of directories
by almut (Canon) on Apr 25, 2007 at 11:41 UTC

    Can't replicate what you're reporting... (Suse Linux 10.1 here — though that shouldn't matter)

    I tried it with several versions of Perl from 5.8.4 - 5.8.8. I always get

    $ PERL5LIB=~/foo:~/bar perl -V (...) %ENV: PERL5LIB="/home/ab/foo:/home/ab/bar" @INC: /home/ab/foo /home/ab/bar /usr/local/perl-5.8.8/lib/5.8.8/x86_64-linux /usr/local/perl-5.8.8/lib/5.8.8 (...)

    (same thing if you export PERL5LIB in a separate shell command, of course...)

    Could you provide a ready to run test case that demonstrates your problem?

      Is it of any significance that you use the variable PER5LIB?
      In my bash script I create an environment variable PERLLIBDIR and in the perl script I refer to it by %ENV{PERLLIBDIR}

        yes, PERL5LIB is a special env variable for just that purpose :)

        In case you'd rather make use of PERLLIBDIR, something like use lib split /:/, $ENV{PERLLIBDIR}; in your script should work as well.

        (I suppose the '%' in %ENV{...} was just a typo...)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-24 19:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found