Hi chennaiite,
That's a pretty open-ended question.
If you're interested in comparing files, I'd suggest taking a look at Text::Diff; it will compare 2 files the way the Linux/Unix utility diff does.
If you're interested in how, exactly, the algorithms for comparison work, take a look at Approximate_string_matching. It references the Levenshtein_distance, which is a way of calculating how close a set of strings are to one another.
Furthermore, if you Google for "Levenshtein distance", you'll find sites that provide more detailed analysis of the algorithms, including some, like this one, which present a helpful visual demonstration.
s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/
| [reply] |
If output order doesn't matter, then just sort the two files before diffing. If it kind of matters, i.e. only local reordering is allowed, then you'll need to be more specific, but you can probably sort consecutive groups of lines and compare them:
for i = 1 .. n - k:
if (sort(expected[i..i+k]) != sort(actual[i..i+k])):
print "Mismatch around line ", i
| [reply] [d/l] |
I'm not sure if I understand your question. Do you mean that you want to compare two files and consider them identical if they have exactly the same lines, except that they may not be in the same order? If so, then just sort them before the comparison. It may even be a situation in which calling an external sort program could be sensible, although that would make your program not portable.
| [reply] |
I will analyse all your suggestion and see which one meet my requirement...
Thank you all for the suggestion provided....
| [reply] |
Also, if you have control over the programs that generate the output, you might want to see why the lines are interchanged and fix it so they are not. Barring that, if you can arrange the lines in some other, definite order before comparing them, that would work too.
| [reply] |