Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I was able to program my script to reject anything that is not a number. However, it also rejects numbers that have a decimal point too. So, if I enter a number like 3.45, it will reject that and not continue until I have entered a number like 3.
Here is the code:
Thanks in advance, Bill Hoefermy $LENGTH = 0; while (1) { print "Enter the length!"; "\n"; chomp ($LENGTH = <>); # checking for non-numeric characters if ($LENGTH =~ /\D/){ print "\nPlease enter a number\n"; next; } last if 0 <= $LENGTH and $LENGTH <= 99.99; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Verifying number input
by footpad (Abbot) on Dec 08, 2001 at 08:28 UTC | |
Re: Verifying number input
by japhy (Canon) on Dec 08, 2001 at 06:42 UTC | |
Re: Verifying number input
by rob_au (Abbot) on Dec 08, 2001 at 15:49 UTC | |
Re: Verifying number input
by dvergin (Monsignor) on Dec 08, 2001 at 09:00 UTC | |
by coolmichael (Deacon) on Dec 08, 2001 at 12:08 UTC |
Back to
Seekers of Perl Wisdom