Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Hi,

I have noticed errors in what perl reports for line numbers, and I'm wondering if some light can be shed here. In one script I'm working with:

package Args; use v5.10; use strict; use warnings; print __LINE__, "\n";
prints 4 for the line number when even I can see that it should print 5. This same script reports 162 for the final line number, when it is actually 181. That's a pretty big error! Moreover, if I add a line to the top of the file:
print __LINE__, "\n"; package Args; use v5.10; use strict; use warnings; print __LINE__, "\n";
it prints 1 and 4 .. the original 4 hasn't changed, and the original 162 at the bottom is still 162. If I add a blank line at the top, though, the subsequent line numbers increment properly (though they're still wrong).

To compound the weirdness, I can copy the lines above and paste them into a new file, which is otherwise empty, and the line numbers are correctly reported, though I suspect errors will creep in if I continue working in that new file. I have noticed similar shenanigans in other scripts I'm working with: The line numbering just gets worse as I go along.

Curiously, a web search doesn't find anyone complaining about this, so I thought I'd come here and ask. I'm using v5.14, the dwimperl release, by the way. Maybe I should update to a later release. Anyway, any wisdom you can offer will be greatly appreciated. Thanks.


In reply to Bad line numbers .. bad! by phramus

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others contemplating the Monastery: (9)
    As of 2014-12-27 20:27 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (177 votes), past polls