sách gpt4 ai đã đi

perl - 这个错误是什么意思 : "import is not exported by the exporter module"?

In lại 作者:行者123 更新时间:2023-12-02 08:04:33 27 4
mua khóa gpt4 Nike

如标题所述,我在尝试使用我的 perl 模块时遇到此错误,但我不知道它是什么意思,而且我似乎无法在 Internet 上找到任何明确的结果。我的代码由 3 个文件组成:一个脚本 (myApp.pl),它使用一个模块 (MyLib.pm),而该模块又使用另一个模块 (Secret.pm)。在这里,它们是完整的:

我的应用程序

#!/path/to/perl

my $version = "1.0.0";

use warnings;
sử dụng nghiêm ngặt;
use Testing::MyLib;

MyLib.pm

package Testing::MyLib;

sử dụng nghiêm ngặt;
use warnings;

use Testing::Secret;

secret .pm

package Testing::Secret;

sử dụng nghiêm ngặt;
use warnings;

use Exporter qw( import );
our @EXPORT = ();
our %EXPORT_TAGS = (
'all' => [ qw( MY_CONSTANT )]
);
our @EXPORT_OK = (
@{ $EXPORT_TAGS{all}}
);

use constant MY_CONSTANT => 'bla bla bla';

它们以这种文件结构退出:

/bin/myApp.pl
/lib/perl/Testing/MyLib.pm
/lib/perl/Testing/Secret.pm

错误消息的详细信息是:

[user@pc ~]$ myApp.pl
"import" is not exported by the Exporter module at /###/lib/perl/Testing/Secret.pm line 6
Can't continue after import errors at /###/lib/perl/Testing/Secret.pm line 6
BEGIN failed--compilation aborted at /###/lib/perl/Testing/Secret.pm line 6.
Compilation failed in require at /###/lib/perl/Testing/MyLib.pm line 6.
BEGIN failed--compilation aborted at /###/lib/perl/Testing/MyLib.pm line 6.
Compilation failed in require at /###/bin/myApp.pl line 7.
BEGIN failed--compilation aborted at /###/bin/myApp.pl line 7.

1 Câu trả lời

使用 Exporter qw( import ); requests Exporter 在模块的命名空间中导出(创建)nhập khẩu。这是处理从您的模块导出的请求的方法。低于 5.57 的 Exporter 版本无法识别此请求,从而导致您收到错误消息。

自 Perl 5.8.3 以来,Exporter 5.57 或更新版本已与 Perl 捆绑在一起,您必须拥有相当古老的 Perl 版本和模块!

您可以升级 Exporter,或者您可以从 Exporter 继承 nhập khẩu,这有点困惑但适用于任何版本的 Exporter。

package MyPackage;
sử dụng nghiêm ngặt;
use warnings;
use Exporter;
our @ISA = 'Exporter';
our @EXPORT_OK = ...;

关于perl - 这个错误是什么意思 : "import is not exported by the exporter module"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53074342/

27 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com