我在同一位置有一个.pm和.pl文件。当我执行该文件时,它运行良好。当我把.pm和.pl文件放在不同的位置时,我会得到这个错误。如何处理,请分享您的意见。感谢你的帮助!
[sjothili@localhostscript]$perl-fapatch-prereq.pl在@INC中找不到Fapatching.pm(@INC包含:/usr/local/lib64/perl5//usr/local/share/perl5/usr/lib64/perl5/vendor_perl/usr/lib64/prl5/usr/share/perl5.(,位于fapatch-prereq.pl第3行。
[sjothili@localhost Apr3]$ pwd
/scratch/sjothili/perl/Apr3
enter code here
猫Fapatching.pm
#!/usr/bin/perl
package Fapatching;
sub doSystemCommand
{
$systemCommand = $_[0];
print LOG "$0: Executing [$systemCommand] n";
$returnCode = system( $systemCommand );
if ( $returnCode != 0 )
{
die "Failed executing [$systemCommand]n";
exit 0;
}
}
1;
cat fapatch-prereq.pl
#!/usr/bin/perl
require Fapatching;
Fapatching::doSystemCommand("pwd");
[sjothili@localhostApr3]$perl-fapatch-prereq.pl/scratch/sjothili/perl/Apr3
[sjothili@localhost script]$ cd ..
[sjothili@localhost Apr3]$ pwd
/scratch/sjothili/perl/Apr3
[sjothili@localhost Apr3]$ cd script/
[sjothili@localhost script]$ ls
fapatch-prereq.pl
`enter code here`[sjothili@localhost script]$ perl fapatch-prereq.pl
Can't locate Fapatching.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at fapatch-prereq.pl line 3.
您没有指定Fapatching.pm
的位置,所以假设您有以下(非常常见的(目录结构:
$project_home/bin/fapatch-prereq.pl
$project_home/lib/Fapatching.pm
您可以通过在脚本中添加以下内容来解决此问题:
use FindBin qw( $RealBin );
use lib "$RealBin/../lib";
根据您的需要进行调整。
向脚本中添加use lib
语句将把该特定脚本的目录添加到@INC
中。不管是谁,在什么环境下运行它。从这里介绍。
use lib '/folder1/folder2/package';
use Fapatching;
感谢作者:Gabor Szabo。无论我在这里提到什么,我都不会被再次推荐。