10
这里是我的Perl脚本,其输出:为什么Perl会抱怨“在无效的情况下无用的常量”,但有时候呢?
use strict;
use warnings;
(undef, 1); # no output
(0, 1); # no output
(1, 1); # no output
(2, 1); # "Useless use of a constant in void context at C:\...\void.pl line 7"
(3, 1); # "Useless use of a constant in void context at C:\...\void.pl line 8"
("", 1); # "Useless use of a constant in void context at C:\...\void.pl line 9"
("0", 1); # "Useless use of a constant in void context at C:\...\void.pl line 10"
("1", 1); # "Useless use of a constant in void context at C:\...\void.pl line 11"
我希望在每行警告。 undef
,0
和1
什么是特殊的,导致这种情况不会发生?
我只是想说这个。它在无效使用%s的情况下在无效环境下表示:“此警告不会针对等于0或1的数字常量发出”http://perldoc.perl.org/perldiag.html#Useless-use-of- %s-in-void-context – chilemagic
很好的挖掘文档。虽然没有解释'(undef,1)'。 (扔掉'undef'被认为没有丢弃任何东西?) –
@Ted Hopp,我添加了对'undef'的解释。 – ikegami