Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# Is it a real number?

Posted on 2004-03-22
Medium Priority
231 Views
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.
0
Question by:ramble
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 48

Accepted Solution

Tintin earned 800 total points
ID: 10653371
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

LVL 28

Assisted Solution

FishMonger earned 200 total points
ID: 10653437
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

LVL 84

Expert Comment

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

Author Comment

ID: 10893523
Thanks_ramble

Just Ignore the last comment
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
###### Suggested Courses
Course of the Month7 days, 10 hours left to enroll