in reply to Recursive If statement not working.
sub autoSubmit{ print "Would you like the logs submitted? Y\\N?: "; my $autoSubmit = getInput; if ( (lc($autoSubmit) ne "y") and ($autoSubmit ne "n")) { print "You did not enter in Yes or No. Please try again\n"; $autoSubmit = autoSubmit(); } return $autoSubmit; }
However, recursion in this case seems like overkill to me, since you could just use a while loop to do the same thing:
sub autoSubmit{ print "Would you like the logs submitted? Y\\N?: "; my $autoSubmit; while (1) { $autoSubmit = getInput; last if ( (lc($autoSubmit) eq "y") or ($autoSubmit eq "n")); print "You did not enter in Yes or No. Please try again\n"; } return $autoSubmit; }
See last for some info on loop control.
|
---|