Perl looks in the current directory (.) For modules?

Does perl. (current directory) for modules? I cannot install the module directly, and I think I can copy it to a local directory. It's true?

+4
source share
6 answers

perl -V print various properties of your Perl installation, including the default @INC . You should notice . there: yes, the current working directory is looking for modules by default.

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

+14
source

In response to a discussion of Cameron and tchrist in the comments on one of the answers.

You can use this snippet to use modules in the same directory as the script, even if the script is running in a different directory.

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

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

+6
source

Recently, some reason not to rely on . @INC larger than usual, namely that this default behavior is planned to be removed in Perl 5.26. See development release notes here: https://metacpan.org/pod/release/EXODIST/perl-5.25.7/pod/perldelta.pod#and-INC

It is well known that this is done to eliminate vulnerabilities that were noticed in some applications as a result of this behavior. CVEs have not been published publicly (yet).

+5
source

I think this will most likely be the default, as indicated in this post . If your implementation does not do this, the syntax specified in the initial question on this post will allow you to reference the module you need.

0
source

When you unpack the module tarball directory, create its Makefile with an optional library argument with the name of any personal directory in which you want to place the contents of the module:

 $ perl Makefile.PL LIB=~/perllibs 

Then make sure your ~/perllibs included in your $PERL5LIB envariable.

0
source

Perl looks for directories in the @INC array when looking for modules.

Please refer to the following SO question about how this array is constructed (this will tell you how to add the current or home directory):

How is Perl @INC created? (aka What are some ways to influence the search for Perl modules?)

Please refer to the following SO question about how Perl finds the actual file for a module:

How does the Perl program know where to find the file containing the Perl module that it uses?

0
source

Source: https://habr.com/ru/post/1335703/


All Articles