Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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.plBut this isn't really completely satisfactory either since now the filename is fixed to that value...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Reset the effect of #line (patch)
by tye (Sage) on Aug 26, 2013 at 00:41 UTC | |
|
Re: Reset the effect of #line
by Eily (Monsignor) on Aug 25, 2013 at 18:29 UTC | |
by Anonymous Monk on Aug 25, 2013 at 23:27 UTC | |
by Eily (Monsignor) on Aug 26, 2013 at 08:00 UTC |