I have this program that takes an array of words and asks the user to type a sentence containing each of the words from the array:
@words = qw(Hi world thanks);
foreach $word (@words)
{
print "Enter a line with word:$word\n";
chomp($input = <STDIN>);
if($input=~/$word/i)
{
print "Great\n";
} else {
print "Incorrect. Type a line containing $word\n";
}
}
If the user enters input with the word, it works fine. But if he does not, he prints an error message and moves on to the next word. I want it to prompt the user to re-enter the input for the same word. But how? I tried, then it didn’t work.
source
share