![]() |
|
Perl Monk, Perl Meditation | |
PerlMonks |
eval error stackby shmem (Chancellor) |
on Nov 11, 2015 at 21:13 UTC ( #1147503=perlmeditation: print w/replies, xml ) | Need Help?? |
There's the perl special variable $@ which is set at eval errors. It is a global variable, and it is a SCALAR type variable. It gets easily clobbered if you don't proceed with utmost care (tye wrote some nodes about that) and fails to report the really interesting thing, e.g. in nested evals. Consider:
With that code, there's currently no way to get at the real problem, which is in the baz code, where $@ is set to
and gets clobbered by my $foo = eval {...} Of course, the above program would have reported the baz() error, if baz()behaved well:
Nonsensical assignment reported, but where is the error from my $foo = eval { };? Looks like I have to set up a die signal handler, or some such. This is all very confusing and doesn't DWIM. And you cannot rely on $@ being propagated properly, unless you revise any included code that uses eval, which is pretty much anything, because eval is the heart of any perl code. All perl code is somehow evaled. Back to $@ - a SCALAR. Why don't we have @@ as an error stack, and a builtin %@ hash keyed upon the names of the stack frames (e.g. Package::sub or 'eva123') or such? The variables @@ and %@ currently (well, I have perl v5.18.2) work as a regular array/hash. But *@{SCALAR} isn't related to $@ at all. Comments?
perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
Back to
Meditations
|
|