Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Timing user input

by starbolin (Hermit)
on Jul 07, 2008 at 05:00 UTC ( [id://695914]=note: print w/replies, xml ) Need Help??


in reply to Timing user input

#!/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? >


s//----->\t/;$~="JAPH";s//\r<$~~/;{s|~$~-|-~$~|||s |-$~~|$~~-|||s,<$~~,<~$~,,s,~$~>,$~~>,, $|=1,select$,,$,,$,,1e-1;print;redo}

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://695914]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (9)
As of 2024-04-18 08:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found