in reply to Sorting an array of hashes and filenames
The general reason you are having problems is that you are trying to sort both the hashes and the filenames, as if they were equivalent items. They aren't: They are related.
This calls for a Perl hash, which keeps related things together.
I've been trying to adapt one into your code for five minutes or so, and have come to the conclusion that either I don't understand line 3, or there is something completely screwy with your code snippit.
Therefore, pseudo-code to do what you want:
my %file_hashes; foreach my $file ( #List_of_files ) { my $hash = hash_fuc($file); $file_hashes{$hash} = $file; } foreach my $hash ( sort keys %file_hashes ) { print "$hash $file_hashes{$hash}\n"; }
You'll probably want to read up on hashes in Perl. They are useful.
(Edit: Removed brainfart at the end.)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Sorting an array of hashes and filenames
by Anonymous Monk on Jan 14, 2009 at 16:00 UTC | |
by DStaal (Chaplain) on Jan 14, 2009 at 16:07 UTC | |
|
Re^2: Sorting an array of hashes and filenames
by learningperl01 (Beadle) on Jan 14, 2009 at 20:31 UTC | |
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 |