Short answer: NO, not even close!
Longer answer:
#!/usr/bin/perl use strict; use warnings; # 1149595 print "Enter number of days (1..90, no fractions or negative values): +"; my $days = <STDIN>; chomp $days; # if ($days =~ /^\s*1-90-9*\s*$/) { # the numeric "test" is hopeless +ly wrong # the "^\s* allows user to enter leading spaces # regex permits a trailing space to match despite +the chomp # ....BUT, a regex is probably the wrong way to go +... #if (0 < $days && $days <= 90 && $days =~ /^\d\d$/ ) { # makes the + exact test explicit if ( (0 < $days) && ($days <= 90) && ($days =~ /^\d\d$/) ) { # some m +ay prefer this print "Inside if, satisfied the spec: $days \n\n"; } else { print "Days entered do not meet spec: $days \n\n"; # tell the use +r specificly }
Update Added missing "use strict;" --- aaaerg! (and fixed misallignment of some comments).
In reply to Re: Validation of UserInput is a positive Integer or not?
by ww
in thread Validation of UserInput is a positive Integer or not?
by G Nagasri Varma
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |