Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

PERL5LIB mystery

by jalucas (Novice)
on Mar 04, 2009 at 16:54 UTC ( [id://748236]=perlquestion: print w/replies, xml ) Need Help??

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

Hello,

I am having a problem using PERL5LIB. I have a directory 'H:/tools/perl_libs/' that is mapped to a Windows remote drive. My PERL5LIB environment variable is set as:

PERL5LIB="H:/tools/perl_libs C:/Perl_5_8_8_822/lib C:/Perl_5_8_8_822/site/lib"

The following code fails. I expect it to find <H:/tools/perl_libs/Memory.pm> as defined in PERL5LIB, but it does not. The code and the error message are provided below:

Code
use strict; #use lib 'H:/tools/perl_libs'; use Memory; use Does::Not::Exist;
Output
Can't locate Memory.pm in @INC (@INC contains: H:/tools/perl_libs C:/Perl_5_8_8_822/lib C:/Perl_5_8_8_822/site/lib C:/Perl_5_8_8_822/site/lib C:/Perl_5_8_8_822/lib .) at ...

The following code works just fine. Memory.pm is found. For whatever reason, defining my directory with use lib ... works but defining in PERL5LIB doesn't seem to. The use Does::Not::Exist; is used to cause a failure and dump the @INC array. Note that <H:/tools/perl_libs> appears as the first two entries in @INC.

Code
use strict; use lib 'H:/tools/perl_libs'; use Memory; use Does::Not::Exist;
Output
Can't locate Does/Not/Exist.pm in @INC (@INC contains: H:/tools/perl_libs H:/tools/perl_libs C:/Perl_5_8_8_822/lib C:/Perl_5_8_8_822/site/lib C:/Perl_5_8_8_822/site/lib C:/Perl_5_8_8_822/lib .) at ...

Does anyone know why the use lib ... would work but PERL5LIB wouldn't?

Thanks.

Replies are listed 'Best First'.
Re: PERL5LIB mystery
by Corion (Patriarch) on Mar 04, 2009 at 17:00 UTC

    See perlrun on PERL5LIB:

    If PERL5LIB is not defined, PERLLIB is used. Directories are separated (like in PATH) by a colon on unixish platforms and by a semicolon on Windows (the proper path separator being given by the command perl -V:path_sep).

    The list of paths is not a whitespace delimited list, but (on Windows) a semicolon-delimited list, like $ENV{PATH}.

      That was it. I switched the spaces to semicolons, and it works great.

      Thanks a lot for the help.

Re: PERL5LIB mystery
by toolic (Bishop) on Mar 04, 2009 at 17:12 UTC
    After heeding Corion's advice...

    To check if PERL5LIB is really taking effect:

    print "$_\n" for @INC;
Re: PERL5LIB mystery
by sundialsvc4 (Abbot) on Mar 04, 2009 at 17:26 UTC

    In general, use lib is more favorable. (Indeed, in “taint mode” it is required.) The reason is... that “the program always works.” Its success vs. failure isn't governed (nor can it be usurped...) by “something in its surrounding environment.”

    Bear in mind, as usual, that in a Windows environment Perl still “speaks Unix,” i.e. with forward slashes, precisely so that source-code doesn't have to be changed when moved from one to the other. Many Perl modules are provided, e.g. in the File:: name-space, which provide platform-agnostic handling of such concerns.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2024-04-26 04:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found