sub prompt {
my ($query) = @_; # take a prompt string as argument
local $| = 1; # activate autoflush to immediately show the prompt
print $query;
chomp(my $answer = <STDIN>);
return $answer;
}
sub prompt_yn {
my ($query) = @_;
my $answer = prompt("$query (Y/N): ");
return lc($answer) eq 'y';
}
if (prompt_yn("Do you want to start a process")){
my $list1 = prompt("Enter ID:\n");
my $list2 = prompt("Enter Name:\n");
print $list1;
print $list2;
## $list1 and $list2 will be used in the code here..
#...
#.....
}
I want to repeat the contents of the if
block again and again, prompting again each time it completes if I press y from (Y/N)
.
我想一次又一次地重复if块的内容,如果我从(Y / N)按y,则每次完成时再次提示。
1 个解决方案
#1
Replace
if (prompt_yn("Do you want to start a process")){
with
while (prompt_yn("Do you want to start a process")){
?
#1
Replace
if (prompt_yn("Do you want to start a process")){
with
while (prompt_yn("Do you want to start a process")){
?