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

I am using a version of Perl which no longer has the directory from which the application has been started in the @INC array. Therefore '.' is not in @INC.
I used
use lib dirname($0) ;
to add the application directory.
At one site this gave a path with backwards leaning slashes like
\\aaa\bbb\ccc
I am having some troubles using the Perl libraries in the directory ccc. Is it because of the '\'?
If so what is a better way to add to the @INC array so that the equivalent of '.' (or even '.' itself)?

Replies are listed 'Best First'.
Re: Adding to @INC
by haukex (Archbishop) on May 21, 2019 at 15:32 UTC
    Therefore '.' is not in @INC. I used use lib dirname($0);

    Note that these are not equivalent. The former puts the current working directory into @INC, which IMHO is not as portable as an absolute pathname, and the latter puts the path where the script is located (assuming $0 was resolved correctly!) into @INC, the two are not always the same! The better version of the latter is use FindBin; use lib $FindBin::Bin;, which I would recommend.

    I am having some troubles using the Perl libraries in the directory ccc. Is it because of the '\'?

    Since you didn't give us exact error messages or an SSCCE, we don't know and would have to guess.

Re: Adding to @INC
by hippo (Archbishop) on May 21, 2019 at 14:03 UTC

    '.' was removed from @INC by default for security reasons. This is only the default. If you understand and accept the risks you can always put it back in.

    use lib '.';

    Or perhaps more prudently:

    BEGIN { push @INC, '.'; }
Re: Adding to @INC
by Athanasius (Archbishop) on May 21, 2019 at 14:41 UTC
Re: Adding to @INC
by LanX (Saint) on May 21, 2019 at 14:00 UTC
    > use lib dirname($0) ;

    whats wrong with use lib '.'; ?

    > At one site this gave a path with backwards leaning slashes like \\aaa\bbb\ccc

    Windows?

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

       use lib dirname($0) ;
      
      whats wrong with use lib '.'; ?
      
      

      I guess the first adds to @INC the dir the script lives in and the second adds to @INC the dir the script was called from, i.e. user's current dir.

        yeah but that's what he wanted, right?

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery FootballPerl is like chess, only without the dice