in reply to using int and the range function
Please note that it might at first glance seem more appropriate to use the numeric comparison operator ==, but this is not the case here. With the eq operator, you will detect that "4y" is not an integer, while with the == operator will silently do the conversion into an integer and report a wrong result.print "This is an integer\n" if int $input eq $input;
Having said that, I would probably tend to prefer some of the regexes already mentioned such as /^\d+$/ or, used negatively, /\D/.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: using int and the range function
by soonix (Chancellor) on Jan 16, 2015 at 07:42 UTC | |
by Laurent_R (Canon) on Jan 16, 2015 at 07:49 UTC |