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
In reply to Re: lib pragma problem
by samtregar
in thread lib pragma problem
by tamaguchi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |