I wanted to request user input and after a while, if there is no answer, the script should exit. I had a code for this
eval {
local $SIG{ALRM} = sub { die "timeout getting the input \n" };
alarm 5;
$answer = <STDIN>;
alarm 0;
chomp $answer;
};
if ($@) {
$answer = 'A';
}
The alarm timeout works as expected, but I wanted to get additional print instructions after every second decrement that looked like a countdown (for example, for 10 seconds they say β10 ... 9..8..so on) Can anyone -Never help how to enable this feature along with a timeout.
thank
source
share