我有一些模块,想为一些子模块创建别名。这是代码:
#!/usr/bin/perl
package MySub;
use strict;
use warnings;
sub new {
my $class = shift;
my $params = shift;
my $self = {};
bless( $self, $class );
return $self;
}
sub do_some {
my $self = shift;
print "Do something!";
return 1;
}
*other = \&do_some;
1;
它可以工作,但会产生编译警告
名称“MySub::other”仅使用一次:/tmp/MySub.pm 第 23 行可能存在拼写错误。
我知道我可以直接输入no warnings 'once';
,但这是唯一的解决方案吗?为什么 Perl 警告我?我究竟做错了什么?
{
no warnings 'once';
*other = \&do_some;
}
or
*other = \&do_some;
*other if 0; # Prevent spurious warning
我更喜欢后者。对于初学者来说,它只会禁用您想要禁用的警告实例。另外,如果您删除其中一行而忘记删除另一行,另一行将开始警告。完美的!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)