The reason for saying local $@
before calling eval
is to refuse to go to your caller $@
. Itβs rude for a subprogram to modify any global variables (if only one of the declared goals of the subprogram). This is not a problem with top-level code (not inside any subroutine).
In addition, on older Perl, any eval
that is called during the destruction of an object will be clobber global $@
(if the object was destroyed because an exception was thrown from the eval
block) if $@
not localized first. This was fixed in 5.14.0 , but many people still use old Perls.
source share