If I understand your objective correctly, I think you have the hash table backwards. Use the md5sum as the key and push each file name that matches onto an Array of Hash. Something like this (untested):
#!/usr/bin/perl
use warnings;
use strict;
use Data::Dumper;
##############
my $dir = shift @ARGV;
my %md5_2file;
opendir(my $dh, $dir) || die "Unable to Open the Directory $dir $!\n";
chdir $dir or die "Cannot Change to directory $dir: $!\n";
while (my $file = readdir $dh) {
if (-f $file) { #takes care of ./ dir's and also no need to chomp(
+)
my ($md) = (split /\s+/, qx(/usr/bin/md5sum $file))[0];
push @{$md5_2file{$md}), $file;
}
}
closedir($dh);
foreach my $md5 (keys %md5_2file)
{
print "$md5: @{md5_2file{$md5}}\n"; # md5: file2 file2 filen
# this md5 is unique if ( @{md5_2file{$md5}} == 1)
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.