in reply to Comparing two files

Use our very own davorg's Array::Compare
#!/usr/bin/perl -w use strict; use Array::Compare; my $comp = Array::Compare->new(Sep => '|', WhiteSpace => 0, Case => 0) +; my $file1 = "/etc/modules.conf"; my $file2 = "/etc/modules.conf2"; open FILE1, $file1 || die "Can't open file 1:$!\n"; my @lines1=<FILE1 +>; open FILE2, $file2 || die "Can't open file 2:$!\n"; my @lines2=<FILE2 +>; if ($comp->compare(\@lines1, \@lines2)) { print "Arrays are the same\n"; } else { print "Arrays are different\n"; }

Replies are listed 'Best First'.
Re: Re: Comparing two files
by davorg (Chancellor) on May 22, 2001 at 11:59 UTC

    Thanks for the plug :)

    Worth pointing out a couple of things:

    1. This depends on reading your files into memory. If your files are large, this might not be such a good idea.
    2. You should only change the 'Sep' character to something that won't appear in your data. In general the default value (^G) is fine.

    "Perl makes the fun jobs fun
    and the boring jobs bearable" - me