My_Module
- 模块(在此包中使用)use
s Signals::XSIG并设置$XSIG{'WINCH'}[1] = sub { ... };
use warnings;
use 5.014;
package Auto_sid;
use Exporter 'import';
our @EXPORT = qw(something);
use My_Module;
no warnings qw(redefine);
sub My_Module::list_to_big {
my ( @arguments ) = @_;
require Signals::XSIG;
Signals::XSIG->import(%Signals::XSIG::XSIG);
@{$Signals::XSIG::XSIG{'WINCH'}} = ();
no Signals::XSIG;
# ...
# do something that My_Module normaly doesn't do and
# which doesn't work when modified $SIG{'WINCH'}
# ...
}
当我使用它时,我收到很多错误消息,如:
"NUM63" is not exported by the Signals::XSIG module
"ARRAY(0xc23180)" is not exported by the Signals::XSIG module
"TRAP" is not exported by the Signals::XSIG module
"ARRAY(0xc119c8)" is not exported by the Signals::XSIG module
...
当我使用use
代替require
时,它可以正常使用
为什么这不适用于require
?
答案 0 :(得分:4)
因为当你这样做时:
Signals::XSIG->import(%Signals::XSIG::XSIG);
您将该哈希的内容传递给导入例程。由于NUM63
和TRAP
是信号名称,并且它们不是Signals :: XSIG的有效导出,因此您会收到这些错误。
你需要这样做:
Signals::XSIG->import('%XSIG');
因为它识别Exporter
将字符串'%XSIG'
识别为 导出的内容之一。
答案 1 :(得分:3)
use Signals::XSIG qw( %XSIG );
相当于
BEGIN {
require Signals::XSIG;
Signals::XSIG->import(qw( %XSIG ));
}
而不是
# Passes the string '%XSIG'
Signals::XSIG->import(qw( %XSIG ));
你做了
# Passes the contents of %Signals::XSIG::XSIG
Signals::XSIG->import(%Signals::XSIG::XSIG);
import
抱怨您传递给它的所有错误值。
(你也摆脱了BEGIN
,但这与你目前得到的错误无关。)