in reply to Checking whether a $var is a number
You need the initial check to make sure that $var actually contains something, otherwise the !~ will trigger a warning about unitialized variables.if ($var && $var !~ /\D/) { # We have a value and it's a number }
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! :)sub isNum { if ($var && $var !~ /\D/) { return 1; } else { return 0; } }
(Yes, I'm sure someone's already done this, but this was too cool an opportunity to promote module use. *blush*)
------
We are the carpenters and bricklayers of the Information Age.
Vote paco for President!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Checking whether a $var is a number
by wog (Curate) on Sep 05, 2001 at 00:32 UTC | |
by Ted Nitz (Chaplain) on Sep 05, 2001 at 01:01 UTC |