Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Perl look in the current directory (.) for modules?

Tags:

module

perl

Does Perl look in . (the current directory) for modules?

I can't directly install a module and I think I could copy it into the local directory. Is this true?

like image 948
Leo Izen Avatar asked Nov 29 '22 03:11

Leo Izen


2 Answers

perl -V will print out various properties about your Perl installation, including the default @INC. You should notice a . in there: yes, the current working directory is searched for modules by default.

(If not, you can use environment variables PERL5LIB or PERLLIB, or -I on the command line, or add a sitecustomize.pl to perl -V:sitelib.)

like image 155
ephemient Avatar answered Dec 05 '22 21:12

ephemient


In response to Cameron and tchrist's discussion in the comments to ephemient's answer.

You may use this snippet to use modules in the same directory as the script, even if the script is executed while in another directory.

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

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

like image 26
Joel Berger Avatar answered Dec 05 '22 20:12

Joel Berger