[Israel.pm] eval inside DESTROY

Shmuel Fomberg semuelf at 012.net.il
Thu Mar 8 09:08:58 PST 2007


Hello There.

A word of warning: if you ever do eval inside a DESTROY function, always
do "local $@" before it.

sub DESTROY {
   local $@;
   eval { close $fh };
}

And why is this? I had a die statement inside my program, that was catch
by an eval. the strange thing was that $@ was empty after the eval.
after much investigation, I discovered that the die caused the
destruction of a few object. one of these objects had an 'eval' inside
the DESTROY sub. that eval finished successfully, and cleared the $@.

Good night,
Shmuel.





More information about the Perl mailing list