Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re: floating point validationby aquarium (Curate) |
on Aug 31, 2010 at 00:40 UTC ( [id://858103]=note: print w/replies, xml ) | Need Help?? |
to get something more generic that is further extensible or easily changed, write a function that produces a (contrived) format of the input as its output. then you can easily change the truth conditional to fit purposes of the day. first check that it's a number by adding zero and testing it still equals original input/number. then decide whether you need signed or not, with or without thousands separator, scientific notation, etc. i assume most of these can be excluded, apart from "not a number" result. then convert all digits and the decimal point to something like d->5->2 or similar, this return value scheme meaning the result is a number (the d), with 5 digits, and decimal point (if any) after second digit. a "not a number" result encoding could be something like "x" or "a" instead of "d". anyway, some form of easily parsable return code of this or similar kind is then easily tested for any preference of conditional, e.g. only want d->4->2 as per the example presented. hope it makes sense.
the hardest line to type correctly is: stty erase ^H
In Section
Seekers of Perl Wisdom
|
|