Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Time-limited input on STDIN

by adrianh (Chancellor)
on Aug 08, 2003 at 22:20 UTC ( #282330=note: print w/ replies, xml ) Need Help??


in reply to Time-limited input on STDIN

Something like:

use strict; use warnings; use Term::ReadKey; sub timed_input { my $end_time = time + shift; my $string; do { my $key = ReadKey(1); $string .= $key if defined $key; } while (time < $end_time); return $string }; my @words = split ' ', timed_input(10);

should do the job.


Comment on Re: Time-limited input on STDIN
Download Code
Re^2: Time-limited input on STDIN
by Ackolight (Initiate) on Apr 07, 2009 at 23:21 UTC
    Hi Adrian,

    Just wanted to say thanks. Although it was not my query originally, I found your method worked in the situation I needed, whereas the other methods utilising SIG don't seem to work under ActivePerl on Windows.

    Just one tweak: a line before the return to prevent it complaining about uninitialised values:

    $string= defined $string ? $string : "No input" ;

    Thanks again. :)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2015-07-05 22:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (68 votes), past polls