Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: Comparing two files

by Tuna (Friar)
on May 22, 2001 at 06:28 UTC ( [id://82151]=note: print w/replies, xml ) Need Help??

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

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://82151]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (1)
As of 2024-05-23 12:19 GMT
Find Nodes?
    Voting Booth?

    No recent polls found