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


In reply to Re: lib pragma problem by samtregar
in thread lib pragma problem by tamaguchi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.