http://www.perlmonks.org?node_id=255779
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Okay, I figured this would be easy, and if not, would be simple to find, but most of what I'm finding is overkill. I want to check user input for a single digit. 0-9, but not 10, 11, 12, 200, 1a, 2b, etc. I thought that /\d/ only returned a single-digit number, but it's also returning double digits. Here's what I"m working with.
$input = <STDIN> if ($input =~ /\d/) { print "input was a single digit number\n"; } else { print "input wasn't a single digit number\n"; }
I also tried:
$input = <STDIN> if ($input =~ /[0-9]/) { print "input was a single digit number\n"; } else { print "input wasn't a single digit number\n"; }
which works but will return true for input like 2a, 22, 33, 5dfsdf I need it to return true only if the number is single digit. In goofing around, I found that this does work...
my $number; chomp ($number = <STDIN>); if ($number < 10) { print "input was either 0-9 or -\n"; }
...except for something like 2a, which in Perl's eyes is 0, no?