[EMAIL PROTECTED] (Prahlad Vaidyanathan) writes:
> Is there a perl equivalent of the 'trap' command in bash ?
> The reason I ask is, I create a temporary file at the
> start of a script, and I want to ensure that that
> temporary file gets removed in case the user hits C-c
> before the script finishes running.
Look at the %SIG (for signal) hash. Here's an (untested)
stub.
sub INT_handler {
#your code goes here
exit; # if you really want to exit program.
}
$SIG{HUP} = 'IGNORE';
$SIG{STOP} = 'DEFAULT';
$SIG{INT} = \&INT_handler;
If you merely "return" from the handler, the interrupt will
get caught, handled, but *not* exit your program. Some
times this is good behavior -- a C-c can do a "reset", for
instance.
Check out "stty -a" from the command line. C-c is probably
mapped to INT. That's why I stubbed out that key.
--
Michael R. Wolf
All mammals learn by playing!
[EMAIL PROTECTED]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]