in reply to Handling Hash Comparison
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 |