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..
#...
#.....
}
我想一次又一次地重复if
块的内容,如果我从(Y/N)
按y,则每次完成时再次提示。
答案 0 :(得分:2)
替换
if (prompt_yn("Do you want to start a process")){
与
while (prompt_yn("Do you want to start a process")){