Thanks Huck and Keybot . From your solution, It is clear to use md5dum's as the keys of the hash and then hash value as a reference to an array of files . I have changed my original code to create a Hash of an Array to do this.

#!/usr/bin/perl use warnings; use strict; use Data::Dumper; ############## my $dir = "$ARGV[0]"; my %md5sum; opendir(my $dh, $dir) || die "Unable to Open the Directory: $!\n"; chdir $dir or die "Cannot Change directory: $!\n"; while (my $file = readdir $dh) { chomp $file; next if $file =~ /^\.{1,2}$/g; if (-f $file) { my ($md) = (split /\s+/, qx(/usr/bin/md5sum $file))[0]; if (exists $md5sum{$md}) { push @{$md5sum{$md}}, $file; } else { push @{$md5sum{$md}}, $file; } } } closedir($dh); foreach my $ky (keys %md5sum) { if (scalar( @{$md5sum{$ky}}) == 1) { print "Unique File: @{$md5sum{$ky}} , Md5sum: $ky\n"; } else { print "Duplicate Files: @{$md5sum{$ky}}, Md5sum: $ky\n"; } }
-bash-3.2$ ./duplicate_files.pl directory Duplicate Files: file4 file2 file3, Md5sum: d41d8cd98f00b204e9800998e +cf8427e Unique File: file6 , Md5sum: d617c2deabd27ff86ca9825b2e7578d4 Duplicate Files: file1 file5, Md5sum: 5bb062356cddb5d2c0ef41eb2660cb0 +6

In reply to Re^2: List Duplicate Files in a given directory by pr33
in thread List Duplicate Files in a given directory by pr33

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.