in reply to Re: Check for Positive Integer entry only
in thread Check for Positive Integer entry only
Close. I think ($_ eq int($_) && $_ > 0) will work as a condition though.
use strict; use warnings; my @tests = qw/12 1a 4 -3 0 0.1 .1/; for (@tests) { print "$_ => "; no warnings qw/numeric/; if ($_ eq int($_) && $_ > 0) { print 'ok'; } else { print 'bad'; } print "\n"; } __END__ C:\Perl\test>perl int_test.pl 12 => ok 1a => bad 4 => ok -3 => bad 0 => bad 0.1 => bad .1 => bad
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Check for Positive Integer entry only
by kyle (Abbot) on May 09, 2007 at 21:59 UTC |