From: David Nicol Date: Fri, 21 Mar 2008 12:56:12 +0000 (-0500) Subject: Re: local $@ has an unwanted side effect X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8a5a710d2a11ee78ddb137b0ff2b5ca547dc295d;p=p5sagit%2Fp5-mst-13.2.git Re: local $@ has an unwanted side effect From: "David Nicol" Message-ID: <934f64a20803211056q5148027ava77af36f51c96418@mail.gmail.com> (with Tim Bunce's amendments) p4raw-id: //depot/perl@33558 --- diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index e0b8049..886aae9 100644 --- a/pod/perlfunc.pod +++ b/pod/perlfunc.pod @@ -1625,6 +1625,22 @@ normally you I like to use double quotes, except that in this 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 does I count as a loop, so the loop control statements C, C, or C cannot be used to leave or restart the block.