in reply to Re: (jeffa) Re: uninitialized value
in thread uninitialized value
You can even wrap this up in a function with error handling like this:
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.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; } }
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.
|
|---|