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!
- Perl Gem
- Somethings should be left to the professionals
- Tracking Changes – Part I
- Master Data Management Stress
- Hyperion System 9 Download
- VMWare: How to Optimize for Performance
- Random Q&A
- Types of MDM
- Tracking Changes – Revisited
- I found a bug!