Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Perl 如何将EXPORT_标签导入EXPORTS_OK?_Perl_Module - Fatal编程技术网

Perl 如何将EXPORT_标签导入EXPORTS_OK?

Perl 如何将EXPORT_标签导入EXPORTS_OK?,perl,module,Perl,Module,尝试使用标记对模块导出进行分组时,我希望避免多次列出名称,因此我尝试了以下方法: our %EXPORT_TAGS = ( 'command_types' => [qw(ENQ ACK NAK)], 'commands' => [qw(A B C)], 'status_codes' => [qw(OK FAILED)], 'default' => [ qw(:status_codes :command_types :stat

尝试使用标记对模块导出进行分组时,我希望避免多次列出名称,因此我尝试了以下方法:

our %EXPORT_TAGS = (
    'command_types' => [qw(ENQ ACK NAK)],
    'commands' => [qw(A B C)],
    'status_codes' => [qw(OK FAILED)],
    'default' => [
        qw(:status_codes :command_types :status_codes)
    ]);
our @EXPORT = @{$EXPORT_TAGS{':default'}};
our @EXPORT_OK = @{$EXPORT_TAGS{':default'}};
但不幸的是,Perl5.18告诉了我一些关于
@{$EXPORT\u TAGS{:default'}
(“不能将未定义的值用作数组引用…”)的未定义数组引用的信息。但是,当我删除外部
@{…}
时,Perl不再抱怨,但是结果(数组引用而不是数组)是错误的

我错过了什么

更新:

当我从
:default
中删除冒号时,错误消息消失,但随后我得到一个关于
无法导出symbol::command\u types
的错误。如果我从
:command\u types
中删除冒号,我不会再收到任何错误(此时),但这不会尝试导出名为
command\u types
的符号,而不是标记
command\u types
的所有符号吗

有效的结果是
@EXPORT=qw(status\u codes命令\u types status\u codes)
然后。

根据,您不应该在
%EXPORT\u TAGS
散列中包含标记名的前导冒号

所以你也可以试试这样的东西:

our %EXPORT_TAGS = (
    'command_types' => [qw(ENQ ACK NAK)],
    'commands' => [qw(A B C)],
    'status_codes' => [qw(OK FAILED)],
);
my @default_tags = qw(status_codes command_types commands);
my @default;
push @default, @{$EXPORT_TAGS{$_}} for @default_tags;
our @EXPORT = @default;
our @EXPORT_OK = @default;

@赫康·赫格兰德:你说得对,这是在尝试不同变体的同时编辑出来的。但我希望您同意散列键(例如
:default
)与我看到的错误类型无关。无论如何都已修复。Re:“与我看到的错误类型无关”我现在测试了这个问题,并且如果我包含冒号,我得到了确切的错误(
不能使用未定义的值作为数组引用…
)。如果我删除冒号,它似乎可以正常工作。@Håkon Hægland:那么这意味着Perl编译器实际上会尝试进行哈希查找(错误消息在我看来像是编译器错误)?我认为作业发生在(早期)运行时。但事实上是的:你似乎是对的。你可以使用这样的映射来避免额外的变量:
@EXPORT=map{@{$EXPORT\u TAGS{$\u}}}qw(status\u code command\u types status\u code)@EXPORT_OK=@EXPORT
@U.Windl…你的
映射
想法,但更具动态性:
push@EXPORT,map{${$EXPORT_TAGS{$}(键%EXPORT_TAGS)
(即,如果标签更新过,则无需记住更新
map
命令中的
qw()
)。