gpt4 book ai didi

perl - 在 Perl 中,无法在 @INC 错误中找到 packgeName.pm

转载 作者:行者123 更新时间:2023-12-04 13:59:25 25 4
gpt4 key购买 nike

这是一个模块math.pm有 2 个基本函数加法和乘法:

package Math;
use strict;
use warnings;
use Exporter qw(import);
our @EXPORT_OK = qw(add multiply);

sub add {
my ($x, $y) = @_;
return $x + $y;
}

sub multiply {
my ($x, $y) = @_;
return $x * $y;
}

1;

这是脚本 script.pl调用 add 函数:
#!/usr/bin/perl
use strict;
use warnings;

use Math qw(add);
print add(19, 23);

它给出了一个错误:

can't locate math.pm in @INC <@INC contain: C:/perl/site/lib C:/perl/lib .> at C:\programs\script.pl line 5. BEGIN failed--compilation aborted at C:\programs\script.pl line 5.



如何解决这个问题呢?

最佳答案

use lib

Adding a use lib statement to the script will add the directory to @INC for that specific script. Regardless who and in what environment runs it.

You just have to make sure to have the use lib statement before trying to load the module:

use lib '/path/to/module';
use Math qw(add);
有关设置 @INC 的更多详细信息,请查看:
How do I include a Perl module that's in a different directory

关于perl - 在 Perl 中,无法在 @INC 错误中找到 packgeName.pm,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30659196/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com