in reply to BOfH Random Excuse Generator
Your regex has a little problem. It will match 'y' anywhere in the input, rather than at the beginning of the input string which I think is what you want. Use the ^ assertion to match at the beginning of the string. Also, if you have verified that the user has started his answer with 'y' you don't really need to check explicitly for the string 'yes'.while (<>) { if ($_ eq /yes/ or /y.*/) { print "\n$word1 $word2 $word3 $word4\n"; exit; } else { exit; } }
or even:my $ans = <STDIN>; print "\n$word1 $word2 $word3 $word4\n" if ($ans =~ /^y/);
print "\n$word1 $word2 $word3 $word4\n" if (($ans = <STDIN>) =~ /^y/);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: BOfH Random Excuse Generator
by mexnix (Pilgrim) on May 27, 2001 at 08:45 UTC | |
by virtualsue (Vicar) on May 27, 2001 at 13:06 UTC |