gpt4 book ai didi

perl - 为什么 perl 会针对不同类型的警告提示不同的行?

转载 作者:行者123 更新时间:2023-12-04 22:50:44 25 4
gpt4 key购买 nike

Perl 通常会提示带有实际错误的行,例如当一个变量只使用一次时:

use warnings;
if ( 0 ) {
} elsif ( $test ) { } # line 3
# Name "main::test" used only once: possible typo at testt.pl line 3.

这不适用于使用未初始化的警告 $_ :
use warnings;
if ( 0 ) { # line 2
} elsif ( chomp ) { }
# Use of uninitialized value $_ in scalar chomp at testt.pl line 2.

use warnings;
if ( 0 ) { # line 2
} elsif ( m/test/ ) { }
# Use of uninitialized value $_ in pattern match (m//) at testt.pl line 2.

这是什么原因造成的?这种行为什么时候有用?

最佳答案

perldoc perl5101delta :

The line numbers for warnings inside elsif are now correct.



请注意,此更改仅影响 elsif;您仍然会看到运行时错误/警告给出了语句的开始或结束行号,而不是有问题的代码的实际行:
$ perl
use warnings;
0 ? do {
} : $test ? do {
} : do { };

0 ? do {
} : chomp() ? do {
} : do { };
Name "main::test" used only once: possible typo at - line 3. # correct
Use of uninitialized value $_ in scalar chomp at - line 8. # incorrect

关于perl - 为什么 perl 会针对不同类型的警告提示不同的行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6402385/

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