in reply to Re^4: Getting error when trying to compare two files
in thread Getting error when trying to compare two files

First, one question: are your files guaranteed to be in the same order? If not, can you sort them (using for example the Unix sort utility) according to the same key(s) before you start? If yes, then you can build on the algorithm I have shown above, reading both files in parallel. Please let us know if you have any difficulty with this.

When dealing with this type of problem, I usually follow a two-step approach: first read the two files in parallel in order to extract the "orphans", i.e. lines which are in one file and not in the other in accordance with a comparison key. This produces two files without orphans (therefore having the same line keys and the same number of lines), which I can then easily compare for differences between the lines (for fields not part of the comparison key). This two-step approach is not necessary, it can be done in one go, but it usually makes it easier to process the data and deal with edge cases.

As for line endings, the easiest is probably to start by eliminating all line endings when reading the lines, to make the comparisons independent of line endings, and to add the line endings at the end, when outputting the result.

A simple instruction such as:

$line =~ s/[\r\s]+//g;
should remove any line ending, whether Windows or Unix (or Mac), from the $line string.