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
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