in reply to File comparison

It is working for me with the same file content. Are you sure that there isn't a newline or space at the end of one, but not the other? You should try two things to verify that all is well with your script on your system: 1) compare a file to itself and 2) compare a file to an actual copy of itself. However, I suspect there is some invisible character that is causing the problem. On the command line, try diff file1 file2.

Replies are listed 'Best First'.
Re^2: File comparison
by vparikh (Novice) on Jul 17, 2012 at 17:45 UTC
    Thanks for replying so fast. I tried on the command line and it doesn't show any differences there. If I compare both files to themselves, it works! And I checked both files again and they have the same number of characters, no extra lines. So any idea what else could be causing this problem?

      You've already determined the root cause of the problem was that you weren't closing the files before you were comparing them. But for future reference, there's the cmp utility.

      Believe it or not, there's a special case of two same text files for which diff will report no differences, but cmp will report a difference at the very first byte. Wanna know what it is? :-)

      UPDATE:  It's not made explicitly clear in perldoc File::Compare, but this core module implements the Unix cmp(1) functionality in Perl. This is stated in the README file.

      Very strange. Could you just try wc file1 file2 real quick as independent confirmation that they have the same # of characters/lines?