in reply to Re: (jeffa) Re: uninitialized value
in thread uninitialized value

The solution that merlyn pointed me at is to use a #line directive like described at the very end of perlstyle. (Bug alert, in Perl 5.005 you need to have a blank line before the directive.)

You can even wrap this up in a function with error handling like this:

use Carp; sub my_eval { my ($pkg, $file, $line) = caller(); my $eval_str = qq(\n# line 1 "eval for file '$file' line $line"\n) . shift; if (wantarray()) { my @res = eval($eval_str); return $@ ? confess($@) : @res; } else { my $res = eval($eval_str); return $@ ? confess($@) : $res; } }
But do be warned, your eval takes place in the scope of my_eval, and not the scope of the function you call it from. (ie You cannot access lexicals.) Unless you somewhere explicitly preprocess your code before compiling it you can't solve this generically without inlining repeated logic.

Doing this in Perl generally requires some sophisticated hackery of the kind that gets you talked about. For the record this is exactly the kind of problem that Lisp macros are perfect for, factoring out repetitive logic in a generic way while keeping current scoping.