in reply to sorting an array of hashes by the value of the keys
Is there a good reason why you want an array of hashes each containing a single value? I would have thought that either a single hash or an array of two element arrays might be more appropriate.
For example:
my %hash = (doc1 => 2345, doc2 => 1234, doc3 => 5678, doc4 => 4567);
You could then get a list of the keys that you wanted in the right order with
my @keys = sort {$hash{$a} <=> $hash{$b} }(keys %hash);
or an array of two element arrays:
my @array = (["doc1", 2345], ["doc2", 1234], ["doc3", 5678], ["doc4", 4567]);
In this case you would sort the array with:
my @sorted = sort {$a->[1] <=> $b->[1]} @array;
|
|---|