XP is just a number | |
PerlMonks |
Re: (Buzzcutbuddha - Pack is an alternative) Validating Numbers in CGI Script?by buzzcutbuddha (Chaplain) |
on May 11, 2001 at 00:34 UTC ( [id://79552]=note: print w/replies, xml ) | Need Help?? |
This solution might not be optimal (as it is not very strict and not exactly what you want) but you could also use pack and unpack. As you can see from the code below, I tested the eval, the regex posted by japhy, and two versions of pack, one that stores the number as a double precision float (packstuffD), and one that stores the number as a single precision float (packstuffF). The regex outputs: Whereas both of the packs output:
As you can see, anything that is not a number gets turned into a zero by the pack/unpack process, which is good and harmless, and only returns valid Perl numbers which is not quite what you wanted so this became was a fun little exercise for myself!
In Section
Seekers of Perl Wisdom
|
|