# Is it a real number?

I'm looking for a number somewhere between -10000 and 10000.

if ((\$_ < -9999) || (\$_ >9999)) {
print "\nIt's a number, but out of range\n";
} elsif (\$_ >-10000) && (\$_ <10000) {
print "\nPerfect\n";
} elsif (\$_ is an alpha/number or just contains alpha) {
print"\nNumber expected, this contains other characters\n";
} else {print "\nShouldn't get here\n";}

I specifically need to know how to determine if \$_ is a number or not.
###### Who is Participating?

x

Commented:
Very much depends on your definition of a number, but for the common case, you can use:

\$var='abc';
print "\$var is not a number\n" unless (\$var =~ /\d+\$/);
0

Commented:
unless (\$_ =~ /\D/) { # proceed only if it's an integer

if (\$_ >= -10000  && \$_ <= 10000) {
print  "\nPerfect\n";
}
else {
print "\nIt's a number, but out of range\n";
}
}
0

Commented:
perldoc -q "How do I determine whether a scalar is a number/whole/integer/float?"
0

Author Commented:
Thanks_ramble

Just Ignore the last comment
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.