Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I also tried:$input = <STDIN> if ($input =~ /\d/) { 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...$input = <STDIN> if ($input =~ /[0-9]/) { print "input was a single digit number\n"; } else { print "input wasn't a single digit number\n"; }
...except for something like 2a, which in Perl's eyes is 0, no?my $number; chomp ($number = <STDIN>); if ($number < 10) { print "input was either 0-9 or -\n"; }
|
|---|