gpt4 book ai didi

perl - 如何使用 %EXPORT_TAGS

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

我在“lib”中有一个类似这样的模块,名为 Fool.pm,它基于 the source code of CGI.pm (因为这是我在考虑导出标签时想到的第一个模块):

package Fool;
require Exporter;
@ISA = qw(Exporter);
@EXPORT_OK = qw/raspberry/;
%EXPORT_TAGS = (
':all' => \@EXPORT_OK,
);
1;

和这样的测试脚本:
use lib 'lib';
use Fool qw/:all/;

我尝试运行脚本并获得以下信息:

perl fool.pl
"all" is not defined in %Fool::EXPORT_TAGS at fool.pl line 2
main::BEGIN() called at lib/Fool.pm line 2
eval {...} called at lib/Fool.pm line 2
Can't continue after import errors at fool.pl line 2
BEGIN failed--compilation aborted at fool.pl line 2.


我看不出这里的错误是什么,有人可以帮忙吗?

最佳答案

您的 key 中不应有冒号。另外,我认为必须声明变量 our为了让 Exporter 可以使用它:

our @ISA = qw(Exporter);
our @EXPORT_OK = qw/raspberry/;

our %EXPORT_TAGS = (
'all' => \@EXPORT_OK,
);

关于perl - 如何使用 %EXPORT_TAGS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3177104/

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