Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: prompt and timeout in tests

by webfiend (Vicar)
on Jan 16, 2008 at 02:32 UTC ( #662609=note: print w/replies, xml ) Need Help??


in reply to prompt and timeout in tests

Why do you think you need a timeout? It is considered normal, polite behavior for your program to wait for STDIN to finish at most prompts.

Anyways, another solution to the "yes or no prompt defaulting to no" dilemma is Term::UI and Term::ReadLine (standard in Perl 5.10).

use strict; use warnings; use Term::UI; use Term::ReadLine; my $term = Term::ReadLine->new('test'); # Use default replies if not at interactive prompt $Term::UI::AUTOREPLY = (-t STDIN) ? 0 : 1; my $choice = $term->ask_yn( prompt => 'Your answer?', default => 'n', ); print "You chose '$choice'\n"; code>

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2019-07-15 20:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?