Skip to content

Commit 8a5a710

Browse files
davidnicolrgs
authored andcommitted
Re: local $@ has an unwanted side effect
From: "David Nicol" <[email protected]> Message-ID: <[email protected]> (with Tim Bunce's amendments) p4raw-id: //depot/perl@33558
1 parent 502d923 commit 8a5a710

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

pod/perlfunc.pod

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,6 +1625,22 @@ normally you I<would> like to use double quotes, except that in this
16251625
particular situation, you can just use symbolic references instead, as
16261626
in case 6.
16271627

1628+
The assignment to C<$@> occurs before restoration of localised variables,
1629+
which means a temporary is required if you want to mask some but not all
1630+
errors:
1631+
1632+
# alter $@ on nefarious repugnancy only
1633+
{
1634+
my $e;
1635+
{
1636+
local $@; # protect existing $@
1637+
eval { test_repugnancy() };
1638+
# $@ =~ /nefarious/ and die $@; # DOES NOT WORK
1639+
$@ =~ /nefarious/ and $e = $@;
1640+
}
1641+
die $e if defined $e
1642+
}
1643+
16281644
C<eval BLOCK> does I<not> count as a loop, so the loop control statements
16291645
C<next>, C<last>, or C<redo> cannot be used to leave or restart the block.
16301646

0 commit comments

Comments
 (0)