This bug is just a minor annoyance, but it can slow down debugging if one is not aware of it, so I thought I'd share. The following snippets illustrates it:
if ( 0 ) {
;
}
elsif ( die __LINE__ ) {
;
}
If you run it as written, the output is:
4 at buggy.pl line 1.
Note that the line reported by
die is incorrect. The same bug exists with
warn, and with warnings in general. E.g.
use warnings;
if ( 0 ) {
;
}
elsif ( "$_" ) {
;
}
__END__
Use of uninitialized value in string at buggy.pl line 2.
Curiously, fatal Compile-time errors don't have this problem:
if ( 0 ) {
;
}
elsif ( 0/0 ) {
;
}
__END__
Illegal division by zero at buggy.pl line 4
Stuff happens.
Update: the above examples were run with perl 5.8.6. I haven't looked at other versions. YMMV.
Update 2: thanks to merlyn for the clarification on compile-time vs. run-time behavior, which I originally mis-interpreted as a difference in response between non-fatal and fatal and non-fatal errors.