Oracle DRM Blog

02 Jul, 2009

Perl Tip on check value for numeric or non-numeric

Posted by: Daniel In: Perl

This is a little tip on Perl for those interested. Perl does not distinguish variables between text or numbers. And so when you’re manipulating data or input, you need to be careful and make your own checks first. It may seem simple but also can be way more complicated. For example, what if you have a string that combines numbers at the beginning and string at the end? What if the number is more like an IP address than a real number? What if you have negatives? Here’s a few lines of code you can use to determine the various checks you can do using regular expressions:

if (/\D/) { print “has nondigits\n” }
if (/^\d+$/) { print “is a whole number\n” }
if (/^-?\d+$/) { print “is an integer\n” }
if (/^[+-]?\d+$/) { print “is a +/- integer\n” }
if (/^-?\d+\.?\d*$/) { print “is a real number\n” }
if (/^-?(?:\d+(?:\.\d*)?|\.\d+)$/) { print “is a decimal number\n” }
if (/^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/) { print “a C float\n” }

Enjoy the week guys!

Visitors who read this post, also read:



No Responses to "Perl Tip on check value for numeric or non-numeric"

Comment Form


  • Daniel: Ravi, yes there're a couple of properties needed for Essbase. If you are using v11 DRM, you should have the templates available already. Just check it
  • Daniel: Hi Tonia, use 9.3.1 add-in and it'll work fine unless you absolutely need version 11 features. In that case, we maybe able to help offline. Regards,
  • Daniel: There isn't any documentation as such from version 8. The DRM database structure is very different, you will have to rebuild it. Shouldn't be too hard

About This Blog

My name is Daniel Poon. I am a multi-disciplined business intelligence professional with a strong dynamic career leading Financial Processes, People, BI Systems and Global Projects to accomplishments. Known for passion in implementing process excellence, quality BI solutions and creative innovations. Thanks for visiting my special interest blog.

 Subscribe This Blog For Free Now

Disclaimer: The words, ideas and opinions here are my own. Please don't assume they represent the opinion of my employer, any other person or organization. Do read the Terms of Use. If you would like to quote me, please ask me first or provide a link back.