in reply to setup of a small perl game
#!/usr/bin/perl use strict; use warnings; sub ask_question; my $question_count = 0; 1 while ask_question ++$question_count; exit; sub ask_question { my $question_count = shift; my $wrongs = 3; local $| = 1; for (my $prompt = "This is question $question_count: "; $wrongs --; $prompt = "Incorrect, try again: ") { print $prompt; chomp(my $answer = <>); return 0 if $answer =~ /^q(?:uit)?$/i; return 1 if $answer =~ /^a(?:nswer)?\s+$question_count$/i; } print "Still incorrect. The answer is 'answer $question_count'\n"; } __END__
|
|---|