Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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.

In reply to Re: if-elsif weirdness by hossman
in thread if-elsif weirdness by leriksen

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-19 15:58 GMT
Find Nodes?
    Voting Booth?

    No recent polls found