in reply to Re: Comparing two files
in thread Comparing two files

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

Replies are listed 'Best First'.
(tye)Re: Comparing two files
by tye (Sage) on May 26, 2001 at 01:21 UTC

    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")
Re: Re: Re: Comparing two files
by Beatnik (Parson) on May 26, 2001 at 01:19 UTC
    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.