Sometimes I need to use modules which placed in the same directory where the script is. I can't write use lib qw(./lib); because the script can be called from any current working directory.
Now I write:
use vars qw($lib); BEGIN {$lib = $0; $lib =~ s/[^\/\\]+$//} use lib $lib . 'lib';
Can it be done better?
UPDATE: Thanks to Aristotle for the nice snippet
use File::Spec::Functions qw( rel2abs catdir ); use File::Basename; use lib catdir( dirname( rel2abs $0 ), 'lib' );
In reply to use lib qw(relative path) by ccn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |