Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Handling Hash Comparison

by kvale (Monsignor)
on Jul 23, 2005 at 03:56 UTC ( [id://477416]=note: print w/replies, xml ) Need Help??


in reply to Handling Hash Comparison

It is not clear what you are trying to do, but let me make a guess. I expect that you want to compare file for duplicates and are using MD5 as a signature to do so.

If this is the task, it will go easier if the MD5 signatures are the keys of the hash and the filenames are the file paths. that way, when you come upon a new file, simply calculate its MD5 signature, and see if that signature already exists as a hash key.

Here is some code to illustrate that:

my %file_sig; find( \&find_dup, $root_dir); sub find_dup { my $name = $_; my $full_name = $File::Find::name; my $dir = $File::Find::dir; if (-f $name) { open IN, "<$full_name"; my $digest = Digest::MD5->new->addfile(*IN)->hexdigest; close IN; if (exists $file_sig{ $digest }) { print "$full_name is a duplicate of $file_sig{ $digest }\n"; } else { $file_sig{ $digest } = $full_name; } } }

-Mark

Replies are listed 'Best First'.
Re^2: Handling Hash Comparison
by omega_monk (Scribe) on Jul 23, 2005 at 04:04 UTC
    No, not exactly, I am synchronizing 2 dirs. I updated my post with the rest of the code in readmore tags...

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-05-18 03:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found