Take the 2-minute tour ×

I am looking into rewriting a old application in Perl.

Setting up three packages and running subroutines from them makes a lot of sense for what I'm going to be doing, but I'm not very familiar with setting up packages.

I want the packages to be in the same place as my other Perl scripts, i.e. nothing other than scripts in this bin directory will need to call these packages.

My question is how can I point Perl to know where my packages are (and how do I install them in a place other then the default) and is this an okay/smart thing to do?

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

This is a common task. The PERL5LIB environment variable contains a list of directories to look for a module in. You can also use the the lib pragma to specify directories a specific script should look for module in:


use strict;
use warnings;
use lib "$ENV{HOME}/lib";

You might also want to look into cpanm and local::lib.

share|improve this answer
add comment

If the packages and scripts are in the same location, I'd recommend using FindBin:

use FindBin '$Bin';
use lib $Bin;
share|improve this answer
If they are in the same location, isn't the path already included? –  Dimitar Petrov Jul 17 '12 at 15:41
FindBin isn't deprecated as such, but it does things in a very obscure way and is prone to breaking, as decribed here. I think scriptname is a better bet. –  Borodin Jul 17 '12 at 17:10
@DimitarPetrov : Not necessarily. @INC includes the present working directory (.), not the directory where the script exists. The two are only the same if the script is contained in the current working directory. –  Zaid Jul 17 '12 at 19:55
@Borodin : Thanks for the heads-up, although the link you provided alludes to some bug being fixed now. –  Zaid Jul 17 '12 at 20:10
add comment

Your Answer


