Change 33558 by [EMAIL PROTECTED] on 2008/03/25 09:22:24 Subject: Re: local $@ has an unwanted side effect From: "David Nicol" <[EMAIL PROTECTED]> Date: Fri, 21 Mar 2008 12:56:12 -0500 Message-ID: <[EMAIL PROTECTED]> (with Tim Bunce's amendments)
Affected files ... ... //depot/perl/pod/perlfunc.pod#593 edit Differences ... ==== //depot/perl/pod/perlfunc.pod#593 (text) ==== Index: perl/pod/perlfunc.pod --- perl/pod/perlfunc.pod#592~33314~ 2008-02-14 09:09:37.000000000 -0800 +++ perl/pod/perlfunc.pod 2008-03-25 02:22:24.000000000 -0700 @@ -1625,6 +1625,22 @@ particular situation, you can just use symbolic references instead, as in case 6. +The assignment to C<$@> occurs before restoration of localised variables, +which means a temporary is required if you want to mask some but not all +errors: + + # alter $@ on nefarious repugnancy only + { + my $e; + { + local $@; # protect existing $@ + eval { test_repugnancy() }; + # $@ =~ /nefarious/ and die $@; # DOES NOT WORK + $@ =~ /nefarious/ and $e = $@; + } + die $e if defined $e + } + C<eval BLOCK> does I<not> count as a loop, so the loop control statements C<next>, C<last>, or C<redo> cannot be used to leave or restart the block. End of Patch.