1

I am writing Perl scripts and when I have too many functions, I usually move them all into a library (also good for code reuse). So I usually create a package (e.g. my_lib.pm) and add use lib 'path/to/lib'; use my_lib; to my script.

I wonder if it's possible to skip the use lib 'path/to/lib';, which sometimes gives me trouble since I reorganize my directory hierarchy, and make Perl look for packages in the same dir where the script is running from.

Thank you.

daxim
  • 39,270
  • 4
  • 65
  • 132
David B
  • 29,258
  • 50
  • 133
  • 186

3 Answers3

1

First, i suggest you - "Never mess up with Core Perl and its libraries - never put your lib in among there".

If you want your script look into current dir, then use like:

require "mylibrary/functions.pm";

where mylibrary is a dir that exists the same path as your caller script.

jack
  • 1,415
  • 4
  • 15
  • 22
0

I would put my .pm file into one directory so you can use if from Perl scrips irrespective of their location.

Then create an envrironment variable PERL5LIB with the name of that directory.

justintime
  • 3,601
  • 4
  • 22
  • 37
-1

You need

use lib '.';
gangabass
  • 10,607
  • 2
  • 23
  • 35