Tuesday, July 21, 2009

Use a Perl library relative to the location of your script

I was trying to customize the lib path of my Perl script to dynamically set the location of my modules based on the location of the script.  Since "use" is handled at compile time, this becomes a little difficult.  There are a few options - most need to use the BEGIN block.

I came across a core module on CPAN called FindBin. This module does exactly what I need.

use FindBin;
use lib "$FindBin::Bin/../lib";




No comments:

Post a Comment