gg48gg has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to handle a ctrl-c signal ( $SIG{'INT'} ), but my program is not capturing it. I am pretty sure this is due to the program currently waiting on input from STDIN via IO::Prompt. When I hit ctrl-c, the program stops and my handling doesn't happen. The handler does work if I insert a sleep and interrupt the sleep.
My question, is how can I capture the signal while using IO::Prompt, or do I have to prompt without using that module?#!/bin/perl -w use strict; use IO::Prompt; $SIG{'INT'} = 'INT_handler'; my $PROMPT="Yes or no? [YES,no] :"; while (prompt $PROMPT, -until => qr/YES|n|N/) { print "\nExcuse me? Say again?\n\n"; } my $YES_NO=$_; sub INT_handler { print_info("Caught signal Interupt. Cleaning up..."); exit(0); }
|
|---|