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

any experience why on redhat6.5 is required adding curr dir?
use lib ".";

not needed on rhel6.4. running the same perl version
This is perl, v5.10.1 (*) built for x86_64-linux-thread-multi

Replies are listed 'Best First'.
Re: use lib current directory
by kcott (Archbishop) on Feb 25, 2014 at 09:15 UTC

    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

      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

        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