in reply to Adding script location to include path

Well, this is using core libs, and does what your snippet does:
use FindBin qw($Bin); use lib $Bin;
Not sure how that's "over three lines".

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

Replies are listed 'Best First'.
Re^2: Adding script location to include path
by Aristotle (Chancellor) on Nov 26, 2003 at 23:38 UTC
Re: •Re: Adding script location to include path
by Azhrarn (Friar) on Jul 11, 2003 at 14:23 UTC
    I was referring to FindBin itself, which uses the same libs as the snippet (File::Spec, and File::Basename), and brings in Cwd, Carp, and Config as well. It's not much more (and most likely already loaded by other things anyway) but uneeded in this particular case. :)

    Whichever's easier for you. Either way works fine (at least I think it does.. haven't extensively tested every scenario), and comes in handy.
      But your code also in turn pulls in those libs! Let's experiment:
      $ cat <<END >in-yours use File::Spec; use File::Basename; use lib &dirname(File::Spec->rel2abs($0)); print "$_\n" for sort keys %INC; END $ perl in-yours >out-yours $ cat <<END >in-mine use FindBin qw($Bin); use lib $Bin; print "$_\n" for sort keys %INC; END $ perl in-mine >out-mine $ comm out-yours out-mine Carp.pm Config.pm Cwd.pm Exporter.pm Exporter/Heavy.pm File/Basename.pm File/Spec.pm File/Spec/Unix.pm FindBin.pm XSLoader.pm attributes.pm base.pm lib.pm re.pm strict.pm vars.pm warnings.pm warnings/register.pm $
      So, the only differences are FindBin itself and Exporter::Heavy. Your attempt to avoid Cwd, Carp, and Config are not avoided in the slightest.

      So please, don't try to reinvent the wheel until you know what that wheel is doing.

      -- Randal L. Schwartz, Perl hacker
      Be sure to read my standard disclaimer if this is a reply.