我有一个 Perl 子程序,它询问用户的输入。我在该子例程本身内部执行检查输入的输入是否为有效输入。
如果不是,我想再次调用子程序,让用户这次输入有效的输入。
我的子程序如下:
sub some_routine {
print "Enter a number to select (1) Apple (2) Mango (3) grapes:"
$value=STDIN;
if($value =~ /[^1-3]/ ) {
print "The input is not valid!";
print "Do you want to continue selecting a fruit again (Y or N)?";
$choice = STDIN;
if( $choice eq "y") {
### I want to call the subroutine again to enter input ###
} else {
exit;
}
}
}
那么如何在其中递归一个子程序呢?