|There's more than one way to do things|
string diff and compareby raybies (Chaplain)
|on May 03, 2012 at 20:32 UTC||Need Help??|
So I admit I've got some playing to do, as I've never used Algorithm::Diff, and String::Diff, but here's my current implementation an internal line diff for a text to html diff compare tool I've written.
I wanted to show inline differences. I have two strings that I *know* have some difference in them (thanks to a call to diff).
I put <span> </span> tags around the differences in a string pair. Both in the old string and the new string. (to be used in a 2 column html table showing diffs side by side).
The output from this script looks like the follows.
I guess I'm curious if there's a better way to create spans on a string, and wanted to share this version that was kinda fun, and hear if folks would implement it more idiomatically.
I've been looking at the two modules cited above, it looks might there might be a better way to create multiple spans depending on say multiple changes in the lines, as opposed to the way I do it where I span only from the first and last differences, not taking into account internal matching withing the single string. So that for exampled the last two lines might instead produce multiple spans in a single string: LIke so...
Of course such an implementation may be a pain... so Then again, my current approach might be good enough. :)
As always I find all you experts and your input invaluable in helping me to think of algorithms and the language differently. Thanks ahead of time for any comments.
So how would you do it? :)