Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: if-elsif weirdness

by hossman (Prior)
on May 21, 2003 at 07:03 UTC ( #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? | Other CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2021-08-02 19:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My primary motivation for participating at PerlMonks is: (Choices in context)








    Results (29 votes). Check out past polls.

    Notices?