in reply to Comparing two files

Ofcourse you could use Algorithm::Diff...
#!/usr/bin/perl use Algorithm::Diff qw(diff LCS); use strict; my @seq1 = ("A".."N"); my @seq2 = ("F".."Z"); my @diff = (); my @lcs = (); if (@diff = diff( \@seq1, \@seq2 )) { } # Not equal # Same for (@lcs = diff( \@seq1, \@seq2 ))
Greetz
Beatnik
... Quidquid perl dictum sit, altum viditur.

Replies are listed 'Best First'.
Re: Re: Comparing two files
by Anonymous Monk on May 26, 2001 at 01:09 UTC
    Thanks guys for pitching in.I tried using the Array::compare. Here's my test.I took 15 folders containing the same 285 files.I ran File::compare,diff and array::compare.It took me 14 secs for the first,10min 30 sec for the second and close to 8 min for the third. I need something that's as fast as file::compare but tone that can take care of the whitespace and case issues. Is there any c function or the likes that are available that can be called from my perl code? Ram

      I suggest you check elsewhere in this very thread to see something that will likely be very fast while still being very easy to write. [ I've really grown to like sorting replies by reputation (see your User Settings) ]

      Update: Though, if you want to ignore blank lines, then that won't work. So here:

      my( $lineA, $lineB ); while( 1 ) { $lineA= do { while(<FILE1>){ last if /\S/ }; $_ }; $lineB= do { while(<FILE2>){ last if /\S/ }; $_ }; last if ! defined $lineA || ! defined $lineB; for( $lineA, $lineB ) { s/\s+/ /g; s/^ //; s/ $//; $_= lc $_; } last if $lineA ne $lineB; } if( defined($lineA) || defined($lineB) ) { warn "The files are different!\n"; }

              - tye (but my friends call me "Tye")
      The reason why Algorithm::Diff is slow, is because is has a totally different purpose (but can be used to do what you need). Algorithm::Diff is an implementation of UNIX's diff, which basically shows you the difference between files. Diff is used with patch when bugs are found/fixed.

      Anyway, more information is available on the Algorithm::Diff POD, Dominus has a page on it, and ofcourse, you can check the diff manpages

      Greetz
      Beatnik
      ... Quidquid perl dictum sit, altum viditur.