http://qs321.pair.com?node_id=259642


in reply to if-elsif weirdness

I can confirm that perl 5.8 has exactly the problem you state in terms of citing the "wrong" line number -- on both solaris and (suse) linux. But I haven't found a way to make it do the "right" thing (not even with "# line N" comments, described in perlsyn) -- however the perlsyn man page does have a fair bit to say about using "SWITCH:" and "use Switch;"...

update: Here's a version where I tried (and failed) to get correct line numbers reported for the error:

#!/usr/bin/perl -w use strict; my $string = "ABC"; my $value = undef; if ($string =~ qr(DEF)) { # warning reported here print "foo"; } # line 8 elsif ($string =~ qr(GHI)) { print "bar"; } # line 11 elsif ($value/1000 ne $value) { # warning actually here print "baz"; } else { }
The line with "$value/1000" is still reported by perl 5.8 as "line 5" (where the "if()" block begins). If I put "#line 11" above the start of the "if()" block, then perl picks it up, and presumably any error in any of the conditions would be reported as happening at line 11. That's not much help. (I haven't checked to see whether line-number reporting would work any better with a "switch"-style block -- I guess that might not be a sure thing...)