【问题标题】:Perl Can't locate .pm in @INCPerl 在@INC 中找不到.pm
【发布时间】:2020-07-15 08:23:49
【问题描述】:

我在同一位置有一个 .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 herecat 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.

【问题讨论】:

  • 为什么不能加载到主库lib文件夹中?

标签: perl


【解决方案1】:

您没有指定Fapatching.pm 的位置,所以假设您有以下(非常常见的)目录结构:

$project_home/bin/fapatch-prereq.pl
$project_home/lib/Fapatching.pm

您可以通过在脚本中添加以下内容来解决此问题:

use FindBin qw( $RealBin );
use lib "$RealBin/../lib";

根据您的需要进行调整。

【讨论】:

    【解决方案2】:

    向脚本添加use lib 语句会将目录添加到该特定脚本的@INC。不管是谁在什么环境下运行它。 Referred from here.

    use lib '/folder1/folder2/package';
    use Fapatching;
    

    Thanks to Author: Gabor Szabo。我不推荐,但我在这里提到。

    【讨论】:

    • 我建议不要将路径硬编码到这样的脚本中。可能会导致以后出现维护问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-23
    • 1970-01-01
    • 2019-10-08
    • 2018-01-05
    • 2017-11-21
    • 1970-01-01
    • 2013-05-19
    相关资源
    最近更新 更多