Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
more useful options
 
PerlMonks  

Re: Comparing two files

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

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


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 07: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.
    --
    <http://www.dave.org.uk>

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://82151]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.