Update: Well text editors do re-define CTRL-C to mean copy-to-pasteboard. But they do it for the entire program. This is "well-known" behavior and is assumed to be global for the program. Even text editors do not do, and I do not recommend any context specific re-definition of CTL-C. I figure this is a "bad" idea. CTRL-C should mean something like: "abort" and that is the standard expected definition.
Overriding say $SIG{__WARN__} in a local sense can be a good idea. I use that idea below to add extra info to a WARNING message in a DB subroutine. In this case, its a "non-numeric" operation attempted, or whatever...
However, I would personally not re-define what CTRL-C does within a program. Mileage of course does vary.local $SIG{__WARN__} = sub { my $msg = shift; print STDERR "*******\n"; print STDERR $msg; print STDERR "current DB record: id=", $x->[$dbc_id]\n"; }; ..code that might cause an WARNING follows...
There is a common misperception that signals don't work on Windows Perl. Not true. sleep() is implemented in terms of ALRM and that can and does cause difficulties, but the basic signals do work on Windows XP.
Perl signals are actually easier than old-fashioned raw C signals (in some ways). However that gets into a lot more complex subject.
Update: I don't see much reason to mess with sigtrap.#!/usr/bin/perl -w use strict; $SIG{INT} = 'CtrlC'; for (1..10) { print "$_\n"; sleep(1); } sub CtrlC { print "CTRL-C seen and ignored!\n"; } __END__ Example run:... I am just hitting CTRL-C at various times... C:\TEMP>perl ctrlc.pl 1 2 3 CTRL-C seen and ignored! 4 CTRL-C seen and ignored! 5 6 7 CTRL-C seen and ignored! 8 9 10
In reply to Re: When to use sigtrap, when to assign to %SIG?
by Marshall
in thread When to use sigtrap, when to assign to %SIG?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |