views:

57

answers:

3

Hi,

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.

+1  A: 

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
thanks, also found FindBin useful (http://perldoc.perl.org/FindBin.html).
David B
Read also this one http://stackoverflow.com/questions/1858762/where-do-i-install-perl-modules-that-i-wrote
Night Walker
A: 

You need

use lib '.';
gangabass
Are you sure about that?
Kinopiko
The current directory . is normally in the list of paths that Perl scans. Type 'perl -V' to see.
justintime
A: 

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