There's no need for an "approx_equal" to do fancy
floating point compare. You get the numbers from
a split - so you have strings. Just use string
compare and avoid the uncertainy problems you have
with floating point compare.
At one point in the evolution of my response, I
was relying on strings to avoid this problem. Three
reasons I switched:
-
The original post didn't make it clear that all
numbers would have exactly one decimal point. If
the row contained 305.10, did that count? How
about 305.099?
-
I can never remember if scalars keep both their
string and numeric natures at the same time. After
using a numeric comparison against a given scalar,
is it now just a number, or are both kept around?
(I could find out by research or experimentation,
but the fact that I had to think about it, even
after 10+
years of using Perl, makes me think that I should
avoid this subtlety.)
-
Finally, it was a way to throw in an educational
tidbit "for free". The original author didn't
specify the example very precisely; by including
this in my response, it would hopefully help them
think about it more clearly. (And/or I was showing
off. You decide.)