#!/usr/bin/perl sub catch_alarm { die "Timeout" } for (;;) { eval { local $SIG{ALRM} = \&catch_alarm; undef $!; print "What do you want? >"; alarm 10; if (defined( $line = readline STDIN )) { alarm 0; chomp $line; print "Here's some $line!\n"; } elsif ($!) { die "Read error" ; } }; if ( $@ =~ /Timeout/ ) { print "\nI grow tired of waiting!\n"; } } What do you want? >foo Here's some foo! What do you want? >qlarch Here's some qlarch! What do you want? > I grow tired of waiting! What do you want? >
In reply to Re: Timing user input
by starbolin
in thread Timing user input
by solar_perl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |