in reply to using Algorithm::Diff for floats

It would seems that what you want to do is consider elements the same when they are below a certain delta from each other. The trouble with this is that A::D expects the keygen function to be one "that should return a string that uniquely identifies a given element." Thus it only considers a single element at a time which IMO makes meeting your implied requirment difficult. int() wont cut it as itll make 4.1 and 4.0 the same but not 3.9 and 4.0 which would apparently not be useful to you.

Iirc tye is working on an updated A::D so you may be able to convince him that adding a key comparison function is a good idea. However until that happens I suspect id be looking at customizing A::D to support such. If thats beyond you then who knows, a prolific author like BrowserUK may just pop up with a viable patch until tye gets his evil schemes into CPAN play...


---
demerphq

    First they ignore you, then they laugh at you, then they fight you, then you win.
    -- Gandhi


Replies are listed 'Best First'.
Re^2: using Algorithm::Diff for floats
by jim_neophyte (Sexton) on Jul 27, 2004 at 19:42 UTC

    i do not employ the int() function for this.

    i take the absolute value of the diff and compare to my threshold. if larger than threshold, simply return original string.

    otherwise, get an average of the two values and pump it through sprintf, because comparing floats for equality is dangerous; my understanding is that prevents it from being a number and makes a string.

    the case of &$keyGen(3.9, "4.0 somehow") eq &$keyGen(4.0, "3.9 somehow")

    both calls should return "3.95".

    i just need to figure out how to get my sub to access "$b" when the first parameter is "$a" and vice versa.

    i think i was originally unclear. is this better?