Perl usually complains about the line with the actual error, e.g. when a variable is used only once:
use warnings;
if ( 0 ) {
} elsif ( $test ) { } # line 3
# Name "main::test" used only once: possible typo at testt.pl line 3.
This does not work for warnings on use of uninitialized $_
:
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.
What causes this? When would this behaviour be useful?
perldoc perl5101delta:
The line numbers for warnings inside elsif are now correct.
Note that this change only affects elsif; you will still see runtime errors/warnings give the beginning or ending line number of the statement instead of the actual line of the offending code:
$ 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With