Thursday, December 9, 2010

Perl -- add the script's directory to @INC

Lets say you write a Perl script that includes some local packages, but you want to run the script from a symlink or from in your path. How can you get it to include those packages in your libraries (@INC)?

Near the top of your script place the lines:


use Cwd 'abs_path';
use File::Basename;
use lib dirname( abs_path $0 );


Should work in all cases and on all OSes. (source: http://use.perl.org/~Aristotle/journal/33995)

No comments: