Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: if-elsif weirdness

by hossman (Prior)
on May 21, 2003 at 07:03 UTC ( [id://259659]=note: print w/replies, xml ) Need Help??


in reply to if-elsif weirdness

Assuming I understand your question, you're looking for a generic "Best Practices" rule you can apply to using "if-elsif" to ensure that *if* you have a warning (or die)in the "EXPR" of (one of) the elsif, *then* the line number reported for that warning (or death) will be accurate.

Is that correct?

Assuming youre requirement is to keep using if-elsif, then i don't think there's anything you can do -- short of waiting for a new version of perl that does a better job of reporting the line number.

One thing you can do, is replace all occurences of this...

elsif (EXPR) BLOCK
...with this...
else { if (EXPR) BLOCK }

Using the test case from Node #42078 as an base for an example, use this instead...

#!/usr/bin/perl -w $def = ''; undef $notdef; if($def eq 'foo') { # Line 4 } else { if ($def eq 'bar') { } else { if ($notdef eq "RHS") { # Line 7 } } }
That should accurately cite the warning on Line 7.

Personally, I don't think it's really that big a deal .. just make sure you keep in mind this problem for the future, and if you ever notice any warnings/deaths cited with a line number of some "if (EXPR)" code, then skim down and see if there's an "elsif" that might be the real culprit.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2024-04-24 06:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found