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?
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?
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
.)
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)
Lately there has been some reason to not rely on .
being in @INC
more than usual, namely that this default behavior is scheduled to be removed in Perl 5.26. See the development release notes here: https://metacpan.org/pod/release/EXODIST/perl-5.25.7/pod/perldelta.pod#and-INC
It is generally known that this is being done to address vulnerabilities that were noticed in some applications as a result of this behavior. The CVE(s) have not been released publicly (yet).
Perl searches directories in the @INC
array when searching for modules.
Please refer to the following Stack Overflow question on how that array is constructed (this would tell you how your current or home directory can be added):
Please refer to the following Stack Overflow question on how Perl finds the actual file for the module:
How does a Perl program know where to find the file containing Perl module it uses?
I think it most likely will by default, as indicated in this post. If your implementation does not do so, the syntax referenced in the initial question on that post will allow you to reference the module you need.
When you unpack the module’s tarball directory, build its Makefile
with an optional library argument with the name of whatever personal directory you want the module contents placed in:
$ perl Makefile.PL LIB=~/perllibs
Then make sure you have your ~/perllibs
directory included in your $PERL5LIB
envariable.