in reply to using int and the range function

You could also use something like this:
print "This is an integer\n" if int $input eq $input;
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.

Having said that, I would probably tend to prefer some of the regexes already mentioned such as /^\d+$/ or, used negatively, /\D/.

Je suis Charlie.

Replies are listed 'Best First'.
Re^2: using int and the range function
by soonix (Chancellor) on Jan 16, 2015 at 07:42 UTC

    I think this is closest to the OP's intent, because it also detects if the number doesn't fit into an "integer".

    But I'd change the if condition to
    ... if $input eq int $input;
    because for humans that's easier to parse than
    ... if int $input eq $input;
      Yes, you are right, it makes precedence comprehension a little bit easier. I actually thought of changing it the way you put it when I posted it, but since I tested it under the debugger the way I wrote it, I prefered not to change my post to something untested. In a real program, I would probably change it to make it clearer.
      Je suis Charlie.