On Fri, Feb 27, 2009 at 10:03, Sarsamkar, Paryushan <psars...@ptc.com> wrote:
snip
> I would like to accept some user inputs (using <STDIN>), but it might be
> easier for a user if I can provide the default value, so that they just
> have to press ENTER.
snip
> Do you want to do the normal thing? [yes] :
>
> Do you want to do something strange, tedious, and/or risky? [no] :
>
> What you want as your return address? [...@there] :
snip

Take a look at IO::Prompt*.  It makes things fairly easy, of course,
you could just check to see if they entered an empty string:

#!/usr/bin/perl

use strict;
use warnings;
use IO::Prompt;

#with IO::Prompt
my $prompt = prompt -d => "ask", "Do you want to ask or follow? [ask]: ";
print "$prompt\n";

#without IO::Prompt
$| = 1;
print "Do you want to ask or follow? [ask]: ";
chomp(my $manual = <STDIN>);
$manual = "ask" if $manual eq '';
print "$manual\n";

* http://search.cpan.org/dist/IO-Prompt/lib/IO/Prompt.pm

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to