[sf-perl] use lib: order doesn't seem to matter

Michael Friedman friedman at highwire.stanford.edu
Tue Aug 24 13:16:25 PDT 2010


Hey, one elsif shorter! D'oh, I should've seen that. I've been staring at this code for years and never bothered to optimize it.

As for why not PERL5LIB, see my other message. We're replacing the production library, not adding on in front of it, in this particular case.

Thanks for the shortening!
-- Mike
______________________________________________________________________________
Mike Friedman | HighWire Press, Stanford Univ | friedman at highwire.stanford.edu

On Aug 24, 2010, at 11:40 AM, Randy J. Ray wrote:

> Michael Friedman wrote:
> 
>> I managed a work around for this behavior at my office a while ago. We have each developer set an environment variable containing their personal module path and use that in preference to the default. It requires this at the top of each script, though:
>> BEGIN {
>>    if ( $ENV{PERL_LIB} =~ /\:/ ) {
>>        unshift( @INC, split( /\:/, $ENV{PERL_LIB} ) );
>>    }
>>    elsif ( $ENV{PERL_LIB} ) {
>>        unshift( @INC, $ENV{PERL_LIB} );
>>    }
>>    else {
>>        unshift( @INC, '/path/to/production/lib/perl5' );
>>    }
>> }
>> The colon splitting was added when we realized we wanted to split our perl modules into multiple CVS projects. They're all in one production directory, but in individual project directories for each developer.
> 
> Not meaning to venture into golf territory, but the elsif is unnecessary:
> 
> BEGIN {
>    if ( $ENV{PERL_LIB} ) {
>        unshift( @INC, split( /\:/, $ENV{PERL_LIB} ) );
>    }
>    else {
>        unshift( @INC, '/path/to/production/lib/perl5' );
>    }
> }
> 
> split() will do what you want (return a single-item list) when there is content in PERL_LIB but no ":".
> 
> As to why you'd do this instead of PERL5LIB, PERL5LIB is added to @INC before any "use lib" are processed. This block can be placed in a way such that you control the timing of when the path-elements are added. Different solutions for different folks/problems, and all that...
> 
> Randy
> -- 
> """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
> Randy J. Ray      Sunnyvale, CA      http://www.rjray.org   rjray at blackperl.com
> 
> Silicon Valley Scale Modelers: http://www.svsm.org



More information about the SanFrancisco-pm mailing list