in reply to use lib current directory

G'day viradan,

Welcome to the monastery.

Check perl -V on both OSes.

I'm reasonably certain that '.' has been included in @INC by default on all Perl versions and OSes that I've used; however, I rarely put modules in the current directory so I've had little reason to check this.

On my completely different version and platform (v5.18.1 built for darwin-thread-multi-2level), I see this:

$ perl -V ... @INC: /Users/ken/local/lib/perl /Users/ken/perl5/perlbrew/perls/perl-5.18.1t/lib/site_perl/5.18.1/ +darwin-thread-multi-2level /Users/ken/perl5/perlbrew/perls/perl-5.18.1t/lib/site_perl/5.18.1 /Users/ken/perl5/perlbrew/perls/perl-5.18.1t/lib/5.18.1/darwin-thr +ead-multi-2level /Users/ken/perl5/perlbrew/perls/perl-5.18.1t/lib/5.18.1 .

Update: Just for completeness, and in case you were wondering where it came from, the first path in my @INC is from:

$ echo $PERL5LIB /Users/ken/local/lib/perl

-- Ken

Replies are listed 'Best First'.
Re^2: use lib current directory
by viradan (Novice) on Feb 25, 2014 at 10:04 UTC
    hi Ken,
    thx for hint, however all three rhel versions contain
    ... Compiled at Aug 7 2013 06:31:19 @INC: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .
    with different compilation time ... kind of strange to me
    so far didn't find anything suspicious in rhel release notes
      If adding use lib "."; fixes a problem && "." is included in @INC, then my first thought is that something removes "." from @INC.

      I would think that this removal would have happened inside the perl code, and at compile time - eg inside a BEGIN{} block.
      So that would be the fist place to look.

      If you have a script in which you have included use lib ".";, try inserting immediately *before* that line:
      BEGIN {print "$_\n" for @INC;};
      If that shows you that "." was present during the execution of the BEGIN{} block, then the inclusion of use lib "."; would do nothing more than put "." at the *beginning* of @INC. That is, instead of having "." last in the @INC search path, it is now *first*.
      Could that be the key to the success with use lib "."; in your case ?

      (There are perhaps other scenarios that I've overlooked.)

      Cheers,
      Rob
        taint mode removes . from @INC ... relying on . is like relying on pwd , its unreliable
        hi rob,
        yes, use lib "."; moves the "." to the top - then it works ok
        still doesn't explain why new OS requires moving "." to the top
        1-/local/tmp/test/perlModules/x86_64-linux-thread-multi 1-/local/tmp/test/perlModules 1-/usr/local/lib64/perl5 1-/usr/local/share/perl5 1-/usr/lib64/perl5/vendor_perl 1-/usr/share/perl5/vendor_perl 1-/usr/lib64/perl5 1-/usr/share/perl5 1-.
        with use lib ".";
        2-. 2-/local/tmp/test/perlModules/x86_64-linux-thread-multi 2-/local/tmp/test/perlModules 2-/usr/local/lib64/perl5 2-/usr/local/share/perl5 2-/usr/lib64/perl5/vendor_perl 2-/usr/share/perl5/vendor_perl 2-/usr/lib64/perl5 2-/usr/share/perl5
        cheers,
        dan

      In that case, the issue may be the location of (potentially multiple copies of) modules and the order in which perl is finding them from @INC.

      In the following, note how '.' moves from $INC[-1] to $INC[0] (compare with my earlier perl -V output):

      #!/usr/bin/env perl -l use strict; use warnings; BEGIN { print "BEFORE use lib: @INC[0, -1]" } use lib '.'; BEGIN { print "AFTER use lib: @INC[0, -1]" }

      Output:

      BEFORE use lib: /Users/ken/local/lib/perl . AFTER use lib: . /Users/ken/perl5/perlbrew/perls/perl-5.18.1t/lib/5.1 +8.1

      -- Ken