local $SIG{INT} is a rather strange thing to attempt because that implies that CTRL-C has different meanings at different places in the code. I figure this is a "bad" idea.

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...

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...
However, I would personally not re-define what CTRL-C does within a program. Mileage of course does vary.

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.

#!/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
Update: I don't see much reason to mess with sigtrap.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.