I was working on a quick hack of a script which included a nasty loop that will run for at least an hour. Sometimes I'm an impatient programmer, and don't like having my CPU block for an extended period of time, so I wanted to stop the loop, go in and edit the hack to restart the loop where it left off, and then re-start it later.... so I threw in this code:
BEGIN{ $SIG{INT}=sub{ print $counter, $/ } }
But I'm running this hack on a Win32 box, so ctrl-c failed to trigger my sigtrap. I eventually gave up trying to do it smart and instead just have the thing printing $counter out to STDOUT. It works, but I kind of wish I could have done it right. Does anyone know how to do a good trap like that on a Win32 machine?

In reply to Win32 Interrupts by Adam

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.