Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: prompt and timeout in tests

by webfiend (Vicar)
on Jan 16, 2008 at 02:32 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://662609]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-04-25 20:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found