in reply to Re: Sorting an array of hashes and filenames
in thread Sorting an array of hashes and filenames
foreach my $file ( $fns ) { open(FH, $file) or die "Can't open '$file': $!"; binmode(FH); my $hash = Digest::MD5->new->addfile(*FH)->hexdigest; $file_hashes{$hash} = $file; } foreach my $hash ( sort {$file_hashes{$a} cmp $file_hashes{$b} +} keys %file_hashes ) { print "$hash $file_hashes{$hash}\n"; } } ------------Results--------------- 32e3d09e0c2ff94316410b1444fbbb37a file1.txt 123d087078b62487c1d4c02f4c943af09 file2.txt 3ddbadc770e1c25a91aa186d3b0595945 file3.txt a3ff6417e3b703604c400965330ea6612 file4.txt b78c8fafdb9a5d4df6b36dcd35c56f6aa file5.txt
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Sorting an array of hashes and filenames
by DStaal (Chaplain) on Jan 14, 2009 at 21:27 UTC | |
by learningperl01 (Beadle) on Jan 14, 2009 at 23:28 UTC | |
by DStaal (Chaplain) on Jan 15, 2009 at 14:07 UTC |