in reply to Re: variable based #line directives?
in thread variable based #line directives?

thanks very much for suggesting i look at Test::Builder, was able to modify Test::Builder::Level in my wrapping module and i am now getting the correct line/script number.

just for my edification, can you point me in the direction of some eval #line directive examples? all of the formats i tried before going to Test::Builder did not affect caller() at all. i tried (same code as originally posted, but adding this on line 13 of test.pl):

when i tried the last one, i got 'bad file descriptor', which i don't understand either..

Replies are listed 'Best First'.
Re^3: variable based #line directives?
by Corion (Patriarch) on Aug 21, 2011 at 07:35 UTC

    The #line directive takes hold only for the code compiled within the eval string. So you can only "set" the line number by doing

    my $code = <<CODE; #line 200 die "Hello world"; CODE eval $code; warn $@; __END__ Hello world at (eval 1) line 200.
Re^3: variable based #line directives?
by choroba (Cardinal) on Aug 23, 2011 at 09:45 UTC
    i got 'bad file descriptor', which i don't understand
    eval returns the value of the last evaluated expression. In your case, there is no expression, so eval returns undef, which triggers die. Use something like
    eval qq{#line $l $ld\n1;} or die "$!";
    $@ is more common (and meaningful) after eval than $! (see perlvar).