Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: if-elsif weirdness

by graff (Chancellor)
on May 21, 2003 at 05:32 UTC ( #259642=note: print w/replies, xml ) Need Help??

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...)

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://259642]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (1)
As of 2021-07-31 18:45 GMT
Find Nodes?
    Voting Booth?

    No recent polls found