perlmeditation
tlm
<p>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:
<c>
if ( 0 ) {
;
}
elsif ( die __LINE__ ) {
;
}
</c>
If you run it as written, the output is:
<c>
4 at buggy.pl line 1.
</c>
Note that the line reported by <c>die</c> is incorrect. The same bug exists with <c>warn</c>, and with warnings in general. E.g.
<c>
use warnings;
if ( 0 ) {
;
}
elsif ( "$_" ) {
;
}
__END__
Use of uninitialized value in string at buggy.pl line 2.
</c>
<strike>Curiously, fatal</strike> Compile-time errors don't have this problem:
<c>
if ( 0 ) {
;
}
elsif ( 0/0 ) {
;
}
__END__
Illegal division by zero at buggy.pl line 4
</c>
Stuff happens.
</p>
<small><p><b>Update:</b> the above examples were run with perl 5.8.6. I haven't looked at other versions. YMMV.</p></small>
<small><p><b>Update 2:</b> 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.</b></p></small>
<div class="pmsig"><div class="pmsig-439528">
<p><small>the lowliest monk</small></p>
</div></div>