16.16. Temporarily Overriding a Signal HandlerProblemYou want to install a signal handler only for a particular subroutine. For instance, your subroutine catches SIGINT, and you don't want to disturb SIGINT handling outside the subroutine. Solution
Use
# the signal handler
sub ding {
$SIG{INT} = \&ding;
warn "\aEnter your name!\n";
}
# prompt for name, overriding SIGINT
sub get_name {
local $SIG{INT} = \&ding;
my $name;
print "Kindly Stranger, please enter your name: ";
chomp( $name = <> );
return $name;
}
Discussion
You must use ![]() Copyright © 2002 O'Reilly & Associates. All rights reserved. |
|