Problems? Is your data what you think it is? | |
PerlMonks |
Re: Exploiting Perls idea of what is a numberby graff (Chancellor) |
on Jul 09, 2008 at 03:10 UTC ( [id://696375]=note: print w/replies, xml ) | Need Help?? |
The following snippet is almost certainly not what you want, but I find it instructive...
For me (macosx 10.4 on intel core 2 duo, perl 5.8.6), the output is: Have fun... BTW, the reason for the funny looking condition -- checking matches for both /^-?\.?\d/ and for the more elaborate regex -- was that it seemed like an easy way to keep $numrgx relatively clear and simple, while still making sure that the string contains at least one digit (which $numrgx by itself does not guarantee). (updated the initial match condition that checks for at least one digit, so that it would only accept "\d", "-\d", ".\d" or "-.\d" at the beginning of the string; of course, $numrgx is still faulty, since it allows multiple periods) Another update -- I knew the regex approach above was silly, and I was curious to have a version that would make it easier to test for more boundary cases (where floating point limitations blur the "same/different" distinction), so here's a version with a better regex -- still not perfect, I suspect, but more fun because of the @ARGV options: With that, you can put a pair like "0.123e4 1.230e3" on the command line, and find out that these are the same; and if you do a pair like "0.123e45 1.230e44", these are different. (final update/fix was to add "?" after the first period in $numrgx)
In Section
Seekers of Perl Wisdom
|
|