Thanks for the tip and code. Here is the code that I have that is still not sorting the data correctly. I would like to sort based on the first value as shown under expected results.
#!/usr/bin/perl use strict; use File::Find; use File::stat; use Digest::MD5; find(\&search, "/home/test/"); sub search { my %result; # Make sure we only look at files and end in src extn. if ( -f && /\.src$/i ) { foreach my $files ( $File::Find::name ) { open(FH, $files) or die "Can't open '$files': $!"; binmode(FH); # Get/Create MD5 for the file my $hashValue = Digest::MD5->new->addfile(*FH)->hexdigest; # Store the filename, indexed by hash value, into an arra +y. This # allows us to store multiple files with the same hash va +lue. push( @{ $result{$hashValue} }, $files ); } # Dump out the result hash, sorting by the hash values. foreach my $key ( sort keys %result ) { # Dump out the array of filenames indexed by this hash va +lue. We # could have sorted this list too if we wanted. foreach my $filename ( @{ $result{$key} } ) { print "$key -> $filename\n"; } } } } ------------------------------------------------------ _____Current results______ b78c8fafb9a5d4df6b36dcd35c56f6aa -> /home/test/file1.src f49f62c0d885ea4687d3149ea95c98fd -> /home/test/test2.src 6ebd09e0c2ff94316410b1444fbbb37a -> /home/test/file4.src b1a087078b62487c1d4c02f4c943af09 -> /home/test/file10.src ______Expected results________ 6ebd09e0c2ff94316410b1444fbbb37a -> /home/test/file4.src b1a087078b62487c1d4c02f4c943af09 -> /home/test/file10.src b78c8fafb9a5d4df6b36dcd35c56f6aa -> /home/test/file1.src f49f62c0d885ea4687d3149ea95c98fd -> /home/test/test2.src

In reply to Re^4: Sorting an array of hashes and filenames by learningperl01
in thread Sorting an array of hashes and filenames by learningperl01

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.