That is a bad idea for many reasons.

update: i'm on winblows 9x here, in case you was wonderin';)
Also, exit from a sigint handler is also a bad idea, just as bad as a die, or a warn, or anything, which doesn't actually terminate the program like a kill.

First, that is not the proper way to exit a program after capturing sigint, you gotta kill youself (i found out the hard way), like:

$SIG{INT} = \&zap; sub zap { print "You zapped me!\n"; # do some stuff # you can't die; # kill 6 which is ABRT doesn't work (crash) # under strict in indigoperl for some reason kill 15, $$; # TERM = 15, forgot where you import it from } sleep 1 while 1;
Second, because of the funky stuff that happens when you capture signals in perl, you can do a few things before killing yourself, but you can't go back into an infinite loop, cause things get pretty messed up. I was gonna suggest something like (code recycled from my personal tests):
#!/usr/bin/perl -w use strict; use sigtrap 'handler' => \&CLEANUP, 'INT'; # $SIG{INT}=\&CLEANUP; =head1 modulus (%) explained =pod Binary ``%'' computes the modulus of two numbers. Given integer opera +nds $a and $b: If $b is positive, then $a % $b is $a minus the largest multiple of $b that is not greater than $a. If $b is negative, then $a % $b is $a minus the smallest multiple of $b that is not less than $a (i.e. the result will be less than or equal to zero). =cut $|++; # i like a free flow of ideas &theloopy; sub theloopy { my($a,$b)=(0,0); while(11) { $a = '|' if(($b % 4) == 1); #| $a = '/' if(($b % 4) == 2); #/ $a = '-' if(($b % 4) == 3); #- $a = '\\' if(($b % 4) == 0); #\ print "\r $a$a$a infinite loop"; select(undef,undef,undef,0.25); # sleep $b++; } } sub CLEANUP { print "\n caught \$SIG{INT}",@_,"\n"; my $shallwedie = <STDIN>; print "shall we die (666)\n"; $shallwedie = <STDIN>; chomp $shallwedie; # $SIG{'ABRT'} = DEFAULT; # just make sure # do your cleanup stuff # and then kill yourself #kill 'ABRT', $$; # ABRT = 6 if($shallwedie eq '666') { print "the dying\n"; kill 'TERM', $$; # TERM = 15 kill 6, $$; } else { print "the loopy\n"; &theloopy(); } #exit; }
But as you can see if you run it, it does some weird things (or things i just don't understand, which might be the reason my example/strategy failed, in which case explanation is welcome ;)

update: indeed having a label, and using a goto will not work, and it will crash perl. But what's this you say about about the handler returning someplace?

Ok, it has been my experience that it returns to what your script was doing before, but another sigint will just kill the script, and i that is not desired behaviour.

So there must be some kind of sigint counter?

 
___crazyinsomniac_______________________________________
Disclaimer: Don't blame. It came from inside the void

perl -e "$q=$_;map({chr unpack qq;H*;,$_}split(q;;,q*H*));print;$q/$q;"


In reply to (crazyinsomniac) Re: Re: keyboard input during runtime... by crazyinsomniac
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.