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

Michael Friedman friedman at highwire.stanford.edu
Tue Aug 24 11:23:44 PDT 2010


Ummm... because we created this BEGIN block in perl 4. :-)

Seriously, though, it's convenient to *replace* instead of just *prepend* libs. We also have multiple production copies of our modules in a very few cases (like slowly rolling out a new major release of our code), so we really want to remove any chance of the script getting the default path by accident. 

But yeah, for normal circumstances, PERL5LIB works pretty well.

-- Mike
______________________________________________________________________________
Mike Friedman | HighWire Press, Stanford Univ | friedman at highwire.stanford.edu

On Aug 24, 2010, at 11:19 AM, Garth Webb wrote:

> Why not just set the standard PERL5LIB env which get placed at the beginning of @INC?
> 
> On Tue, Aug 24, 2010 at 11:08 AM, Michael Friedman <friedman at highwire.stanford.edu> wrote:
> David,
> 
> 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.
> 
> -- Mike
> ______________________________________________________________________________
> Mike Friedman | HighWire Press, Stanford Univ | friedman at highwire.stanford.edu
> 
> On Aug 24, 2010, at 10:53 AM, David Alban wrote:
> 
> > greetings,
> >
> > one of our customary 'use lib' statements for a local program is:
> >
> >  use lib '/nas/reg/lib/perl';
> >
> > i'm modifying the program and in my development area, i want to use a
> > locally modified version of one of the modules it uses.
> >
> > but it's picking up the installed module rather than my local module.
> >
> > here's what i'm seeing:
> >
> >  DB<1> l 1+10
> > 1       #!/usr/bin/perl
> > 2
> > 3:      use strict;
> > 4:      use warnings;
> > 5
> > 6:      use lib '/nas/reg/lib/perl';
> > 7
> > 8            ##### => dbg
> > 9:      use lib
> > '/nas/home/dalban/perforce/srwd00reg001/default/internal/reg/pb_reg_nasify_properties/lib/perl';
> > 10           ##### <= dbg
> > 11
> >  DB<2> x @INC
> > 0  '/nas/reg/lib/perl/x86_64-linux-thread-multi'
> > 1  '/nas/reg/lib/perl/5.8.5'
> > 2  '/nas/reg/lib/perl'
> > 3  '/nas/home/dalban/perforce/srwd00reg001/default/internal/reg/pb_reg_nasify_properties/lib/perl'
> >
> > and if i reverse the order in which i "use" them, i get:
> >
> >  DB<1> l 1+10
> > 1       #!/usr/bin/perl
> > 2
> > 3:      use strict;
> > 4:      use warnings;
> > 5
> > 6            ##### => dbg
> > 7:      use lib
> > '/nas/home/dalban/perforce/srwd00reg001/default/internal/reg/pb_reg_nasify_properties/lib/perl';
> > 8            ##### <= dbg
> > 9
> > 10:     use lib '/nas/reg/lib/perl';
> > 11
> >  DB<2> x @INC
> > 0  '/nas/reg/lib/perl/x86_64-linux-thread-multi'
> > 1  '/nas/reg/lib/perl/5.8.5'
> > 2  '/nas/reg/lib/perl'
> > 3  '/nas/home/dalban/perforce/srwd00reg001/default/internal/reg/pb_reg_nasify_properties/lib/perl'
> >
> > i thought 'use lib' had the effect of unshifting its arg onto @INC,
> > but /nas/reg/lib/perl seems to "win" no matter in what order i specify
> > the libs.
> >
> > i've done this before with no problem.  i'm sure i'm missing
> > something.  or perhaps it only seemed to work before...
> >
> > what am i missing?
> >
> > thanks,
> > david
> > --
> > Live in a world of your own, but always welcome visitors.
> > _______________________________________________
> > SanFrancisco-pm mailing list
> > SanFrancisco-pm at pm.org
> > http://mail.pm.org/mailman/listinfo/sanfrancisco-pm
> 
> _______________________________________________
> SanFrancisco-pm mailing list
> SanFrancisco-pm at pm.org
> http://mail.pm.org/mailman/listinfo/sanfrancisco-pm
> 



More information about the SanFrancisco-pm mailing list