Dear Monks,

I am generating perl code from a source perl file, the output is a mix of my generated code and the original source. So that possible errors can keep track of where I am in the original file, I'm outputting #line directives referring to the source file.

The problem is that once I've output a few lines of the original source, I'd like to switch back to having error messages refer to the current file; something like #line __LINE__ __FILE__. I haven't been able to find out how to do this or if it's at all possible.

If you have any ideas that'd be great!

Note: The functions which generate the code don't know what file they are writing to, and keeping track of the current output line seems like a big hassle, so generating #line directives for my own code isn't really possible. The only hack I've been able to come up with so far is generating the file with "#line __LINE__ __FILE__", and then in a second step doing

perl -i -pe 'if(/^#\s*line/) { s/__LINE__/$.+1/e; s/__FILE__/$ARGV/; }' -- generated.pl

But this isn't really completely satisfactory either since now the filename is fixed to that value...


In reply to Reset the effect of #line by Anonymous Monk

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.