i woke up this morning and had a moment of clarity. (thanks for /msging me the link here.) you need to reload the signal handler for it to work again. try this:

#!/usr/local/bin/perl -w use strict; $|++; { # global count, closure my $count=0; # initialize count sub inc_count { ++$count } # increment count sub get_count { $count } # get count } $SIG{INT} = \&_SIGINT_; # set signal handler (CTRL-C) sub _SIGINT_ { # handle CTRL-C inc_count(); # increment global count $SIG{INT} = \&_SIGINT_; # reset signal handler (CTRL-C) }; while(1) { # infinite loop my $count = get_count(); # get the count of CTRL-C's $count % 2 # branch (just to do something) ? printf "\b\b\b\b\b\b\b\byes %2d",$count : printf "\b\b\b\b\b\b\b\b no %2d",$count; sleep 1; # take a cat nap $count >= 10 and last; # break loop (not so infinite) } print "\ndone!\n"; # et voila!
</code> oh, and by the way, if you're running your code on windows, note that kill won't work as you think. specifically, kill will *always* abort the program, and force the exit code to the number you send. it will not send a signal to the program, like it does on unix.

~Particle


In reply to Re: (crazyinsomniac) Re: Re: keyboard input during runtime... by particle
in thread keyboard input during runtime... by Shadowfax

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.