unix - timeout a user input in perl -
i wanted prompt user input , after time , if no response , script must exit . had code
eval { local $sig{alrm} = sub { die "timeout getting input \n" }; alarm 5; $answer = <stdin>; alarm 0; chomp $answer; }; if ($@) { #die $@ if $@ ne "timeout getting input\n"; $answer = 'a'; }
the alarm timeout working expected , wanted additional print statement after every second decrementing similar countdown (like 10 sec " 10 ...9 ..8 ..so on ) please how feature embed along timeout.
thanks
# disable output buffering $| = 1; $answer; eval { $count = 10; local $sig{alrm} = sub { # print counter , set alaram again if (--$count) { print "$count\n"; alarm 1 } # no more waiting else { die "timeout getting input \n" } }; # alarm every second alarm 1; $answer = <stdin>; alarm 0; chomp $answer; }; if ($@) { #die $@ if $@ ne "timeout getting input\n"; $answer = 'a'; }
Comments
Post a Comment