Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^2: file comparison

by Karger78 (Beadle)
on Jun 26, 2009 at 19:58 UTC ( #775159=note: print w/replies, xml ) Need Help??


in reply to Re: file comparison
in thread file comparison

Thanks for your method. i am doing a file compare on windows. will your snip work even if the file names are different but the size is the same?

Replies are listed 'Best First'.
Re^3: file comparison
by ramlight (Friar) on Jun 26, 2009 at 20:13 UTC
    Yes. You just have to feed the appropriate file names to the fc command and look at what it gives you back. It so happened that I was comparing two shares to see where they differed, not quite the same as your problem ... but close enough.
      I decided to do it the md5 way. So how would i accomplish this. I have it reading the directorys assign it to an array. Right now I am just printing the md5 hash from each element in the array. How would I assign each item to the array, and then loop though each array and compare each field?
      opendir(DIR, $RemoteSubDirectory); my @rFileCheck = readdir(DIR); closedir(DIR); opendir(DIR, $localCpPath); my @lFileCheck = readdir(DIR); closedir(DIR); my $c1; foreach (@lFileCheck) { print md5_base64($lFileCheck[$c1]); print "\n"; $c1++; } my $c2; foreach (@rFileCheck) { print md5_base64($rFileCheck[$c1]); print "\n"; $c2++; }
        Let's back up a minute and think about the problem.

        To do the comparison, you need
        - the file to be compared (file_a)
        - the file to compare with (file_b)
        - a method of doing the comparison

        Given two lists of files (@file_a) and (@file_b), then you just need to take one from column a and one from column b, apply the comparision method, and check the result. For example you could:

        $fa = shift(@file_a); $fb = shift(@file_b); if (digest($fa) == digest($fb)) # digest=whatever method you prefer # use eq instead of == if digest retur +ns a string { # files match }
        So you have two separate problems: first generating the two lists of files so that the appropriate files match up in each list, then doing the proper digest.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2022-12-01 19:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?