欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

How to change @INC to find Perl modules in non-standard locations 博客分类: How to change @INC to find Perl modules in non-standard locations PERL 

程序员文章站 2024-03-21 16:02:40
...
How to change @INC to find Perl modules in non-standard locations


Loading your private Perl module
You have a script and have just started to move some parts of it, out to a new module called My::Module. You saved the module to /home/foobar/code/My/Module.pm.

Your perl script now starts like this:

use strict;
use warnings;
use My::Module;

Can't locate My/Module.pm in @INC (@INC contains:
   /home/foobar/perl5/lib/perl5/x86_64-linux-gnu-thread-multi
   /home/foobar/perl5/lib/perl5
   /etc/perl
   /usr/local/lib/perl/5.12.4
   /usr/local/share/perl/5.12.4
   /usr/lib/perl5 /usr/share/perl5
   /usr/lib/perl/5.12
   /usr/share/perl/5.12
   /usr/local/lib/site_perl
   .).
   BEGIN failed--compilation aborted.


On Linux/Unix when using Bash, you would write

export PERL5LIB=/home/foobar/code
You can add this to the ~/.bashrc to make it always available when you log-in.

On Windows you can set the same in the cmd command window by typing

set PERL5LIB=c:\path\to\dir



The last solution is the most temporary solution. Add a -I /home/foobar/code flag to perl when running the script.

perl -I /home/foobar/code script.pl

This will add /home/foobar/code to the beginning of @INC for this specific execution of the script.

https://perlmaven.com/how-to-change-inc-to-find-perl-modules-in-non-standard-locations
相关标签: PERL