in reply to Guess A Number
Another idea for improvement is to put the input in a loop and only exit the loop upon receiving the proper input. This is one way:
my $max; chomp($max = <STDIN>) while(not defined $max && $max =~ m/^[0-9]+$/); my $answer = int(rand($max))+1;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Guess A Number
by sulfericacid (Deacon) on Mar 18, 2003 at 04:32 UTC |