Just another Perl shrine | |
PerlMonks |
Re: Checking whether a $var is a numberby dragonchild (Archbishop) |
on Sep 05, 2001 at 00:24 UTC ( [id://110150]=note: print w/replies, xml ) | Need Help?? |
The really obvious way to do it is to make sure that the scalar doesn't contain a non-numeric character.
You need the initial check to make sure that $var actually contains something, otherwise the !~ will trigger a warning about unitialized variables. So, you can code up a neato little function, sorta like: Then, put that into a module of yours and have that module inherit from Exporter and you're all good! :) (Yes, I'm sure someone's already done this, but this was too cool an opportunity to promote module use. *blush*) ------ Vote paco for President!
In Section
Seekers of Perl Wisdom
|
|