我在同一位置有一个.pm和.pl文件。当我执行文件时,它工作正常。当我将.pm和.pl文件放在不同的位置时,出现此错误。如何处理此问题,请分享您的意见。感谢您的帮助!
[[sjothili @ localhost脚本] $ perl fapatch-prereq.pl在@INC中找不到Fapatching.pm(@INC包含:/ usr / local / lib64 / perl5 / usr / local / share / perl5 / usr / lib64 / perl5 / vendor_perl / usr / share / perl5 / vendor_perl / usr / lib64 / perl5 / usr / share / perl5。)位于fapatch-prereq.pl第3行。
[sjothili@localhost Apr3]$ pwd
/scratch/sjothili/perl/Apr3
[enter code here
cat 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 @ localhost Apr3] $ 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.
向脚本添加use lib
语句会将特定脚本的目录添加到@INC
。不论谁在什么环境下运行它。 Referred from here。
use lib '/folder1/folder2/package';
use Fapatching;
Thanks to Author: Gabor Szabo。我不被推荐,但是我在这里提到了。
您未指定Fapatching.pm
的位置。
假设您有
$project_home/bin/fapatch-prereq.pl
$project_home/lib/Fapatching.pm
您可以通过在脚本中添加以下内容来解决此问题:
use FindBin qw( $RealBin );
use lib "$RealBin/../lib";
根据您的需要进行调整。