Reputation: 209
I want the user to just press enter for the perl script to continue. Example:
# in the line below the 'y' should be given as a suggestion,
# thus only pressing "enter" to continue.
print "Are you over 18? (y/n): ";
chomp(my $allow = <STDIN>);
Upvotes: 2
Views: 82
Reputation: 4532
You can print the carriage return character without a linefeed. This moves the caret to the beginning of the line which then makes any subsequent text overwrite it:
print "Are you over 18? (y/n):\ny\r";
chomp(my $allow = <STDIN>);
$allow ||= "y"; # Accept default if nothing supplied
Upvotes: 2
Reputation: 50657
print "Are you over 18? (Y/n): ";
chomp(my $allow = <STDIN>);
$allow ||= "y";
if (lc($allow) ne "y") {
die "you're not allowed\n";
}
Upvotes: 3