in reply to lib pragma problem

Here's what I do in all my scripts (for example, from Krang):

use File::Spec::Functions qw(catdir splitdir canonpath); use FindBin qw($RealBin); use Config; BEGIN { # Find a KRANG_ROOT based on path to bin my @dir = splitdir(canonpath($RealBin)); $ENV{KRANG_ROOT} ||= catdir(@dir[0 .. $#dir - 1]); # use $KRANG_ROOT/lib for modules my $lib = catdir($ENV{KRANG_ROOT}, "lib"); $ENV{PERL5LIB} = $ENV{PERL5LIB} ? "$ENV{PERL5LIB}:${lib}" : $lib; unshift @INC, $lib, "$lib/".$Config{archname}; }

This uses the location of the script to find a "lib" dir in the parent directory. It then does the equivalent of a "use lib" as well as setting up PERL5LIB so that any sub-processes will use the same modules. You may not need the PERL5LIB setup if you aren't going to run any sub-processes that need to find Perl modules.

This is better than putting a fully-qualified path in your script, in my opinion, because you can move your whole tree around and not change anything. This is particularly useful if you're working with other developers.

-sam

Replies are listed 'Best First'.
Re^2: lib pragma problem
by perrin (Chancellor) on Jan 31, 2008 at 20:11 UTC
    Modern perls don't need the Config{archname} stuff. The lib pragma does that automatically.
      Yeah, I think that's in there for v5.6.0 support on ancient Redhat releases. Probably time to dump it from my template.

      -sam