Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Need way to override PERL5LIB from inside pl script file

by syphilis (Archbishop)
on Jun 25, 2015 at 02:40 UTC ( [id://1131886]=note: print w/replies, xml ) Need Help??


in reply to Need way to override PERL5LIB from inside pl script file

... sets global system environment variable PERL5LIB to its own internal copy of Perl

This is not normally a problem as PERL5LIB does *not* clobber existing @INC.
It merely adds (prepends)the specified path(s) to @INC:
C:\>perl -le "print \"@INC\"" C:/MinGW/perl516/site/lib C:/MinGW/perl516/lib . C:\>set PERL5LIB=C:/rubbish C:\>perl -le "print \"@INC\"" C:/rubbish C:/MinGW/perl516/site/lib C:/MinGW/perl516/lib . C:\>
Seems to me that @INC should still be locating your modules, even though some additional paths have bee prepended to it by PERL5LIB.

Are you sure you've diagnosed the problem correctly ?
I'm wondering whether, perhaps, the wrong perl (ie Oracle's perl) is actually running your perl script.

Cheers,
Rob

Replies are listed 'Best First'.
Re^2: Need way to override PERL5LIB from inside pl script file
by afoken (Chancellor) on Jun 25, 2015 at 08:33 UTC
    PERL5LIB does *not* clobber existing @INC. It merely adds (prepends) the specified path(s) to @INC
    Seems to me that @INC should still be locating your modules, even though some additional paths have bee prepended to it by PERL5LIB.

    This is exactly the problem. The Oracle perl library path is prepended to the non-Oracle perl library path. That means that all modules will be loaded from Oracle's perl, and only if they do not exist there, they will be loaded from the non-Oracle perl. No problem for custom modules installed somewhere in in the non-Oracle library path. For pure-perl modules, this should be no big thing, too. But XS modules will likely cause trouble due to mixing perl versions. Also note that pragmatic modules will be loaded from the wrong perl version. That may also cause trouble due to different internals.

    The only in-perl solution is to clean up @INC before loading any module, including pragma modules. This could happen in a BEGIN block at the top of the perl script. Of course, that BEGIN block could also be implicit, as in use. With a module name that does not exist anywhere in the Oracle perl library path, that module would be loaded from the non-Oracle librariy path. Example:

    File GetRidOfOracle.pm somewhere in the non-Oracle perl library path:

    package GetRidOfOracle; # @INC is messed up, so we must not load any other module here. # This includes "strict" and "warnings". sub isOracleDirectory { my $dirname=shift; # We are on Windows. / and \ are equal. Case does not matter. # Change to local conditions as needed. $dirname=~tr|\\|/|; return lc($dirname)=~m|/oracle/|; } # remove Oracle Directories from @INC: @INC=grep { !isOracleDirectory($_) } @INC; 1;

    Any perl script that may suffer from Oracle's PERL5LIB:

    #!/usr/bin/perl # ^- Change perl path and parameters as needed use GetRidOfOracle; # <-- must be the very first command in the script +! use v5.12; use strict; use warnings; # your code here ... # For a demo, set PERL5LIB as Oracle would do, then run this script. # No Oracle directory should be printed as long as GetRidOfOracle is l +oaded. say for @INC;

    Update:

    I just remembered that the OP uses perl 5.8.0, so the demo won't work. Use this for 5.8.0:

    #!/usr/bin/perl # ^- Change perl path and parameters as needed use GetRidOfOracle; # <-- must be the very first command in the script +! use strict; use warnings; # your code here ... # For a demo, set PERL5LIB as Oracle would do, then run this script. # No Oracle directory should be printed as long as GetRidOfOracle is l +oaded. print "$_\n" for @INC;

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-19 20:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found