PyroX has asked for the wisdom of the Perl Monks concerning the following question:

Very simple question, I am just too tired and it too late at night, hoping for a quick answer. I want to know if I can make it so you can not kill a perl script by typing ctrl c. I need to keep it from being broke. At the same time I am getting input from the user. I am guessing there is not, but thought I would ask.

Replies are listed 'Best First'.
Re: Simple Question
by Zaxo (Archbishop) on Oct 24, 2001 at 10:16 UTC
    local $SIG{INT} = 'IGNORE';

    After Compline,
    Zaxo

Re: Simple Question
by scmason (Monk) on Oct 24, 2001 at 11:25 UTC
    Hi, This can all be taken care of by manipulating the %SIG hash. To catch ^c and handle it in your own sub, try:

    $SIG{QUIT} = \&catchQuit

    where catchQuit is the name of your sub to handle ^c.
    To ignore ^c altogether, try

    $SIG{QUIT} ='IGNORE';
    and to restore it:
    $SIG{QUIT}='DEFAULT'

    PEACE
    scmason

      Just one comment,

      I've tried this code in a Linux Box and in a Win200K Box and does not ignore control-c

      perl -e 'map{sleep print "$_\n";$SIG{QUIT}='IGNORE'}(1..10)'

      $SIG{QUIT} doesn't do it, but $SIG{INT} does it.

      Yes, I know I shouldn't ab(use) map for this...
      Hope this helps
      My apologies. Everywhere I wrote $SIG{QUIT}, I meant $SIG{INT}.
Re: Simple Question
by PyroX (Pilgrim) on Oct 26, 2001 at 23:20 UTC
    Thanks guys