• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 342
  • Last Modified:

perl: How do I check if a line has only numeric characters

I want to check if a line has only numeric characters.  For example, in the log given below line 1 has only numerals but line two has numerals and alpha.  How can I check this?

20110425041121768
20110425041723134	 Java Exception - NullPointerException

Open in new window

0
ambuli
Asked:
ambuli
2 Solutions
 
brutaldevCommented:
if ($string =~ /^\d+$/) { 
 print "$string contains only digits."; 
}

Open in new window

0
 
wilcoxonCommented:
if ($line =~ /^\d+$/) {
   # yes, it is numerals only
}
0
 
ambuliAuthor Commented:
Thank you both of you!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now