On May 30, 2007, at 16:38, David Nicol wrote:

We can declare a line number, in source code, like so
# perl <<foo
#line 54
die smiling
foo
smiling at - line 54.
#

and counting newlines within a Filter::Simple code block is easy enough

but how do I find out what line to start at, so I can insert #line comments into my filter output that will match the input? I am about to experiment with caller(N) to see how many frames back to go, then I'll use that, but I am asking
here in case anyone knows a better way.

caller() is a good solution. I use it, Filter::Util::Call, and some involved #line magic to maintain sane line numbers in Filter::Template. This short example defines a "whatever" template, then expands it inline. The resulting error message follows. (Note that #line directives seriously confuse perl -d. I half-jokingly suggested floating-point line numbers so source filters could insert lines 1.01 through 1.10 between lines 1 and 2 if necessary. But I digress...)

#!/usr/bin/env perl

use Filter::Template;

template whatever (why) {
  die "whatever died: ", why;
}

{% whatever "stuff" %}

__END__

whatever died: stuff at template whatever (defined in moo.perl at line 6) invoked from moo.perl line 9.

--
Rocco Caputo - [EMAIL PROTECTED]

Reply via email to