in reply to Sorting a array of hashes
Making wild guesses about what you may actually be trying to achieve and almost entirely ignoring the minuscule amount of code that you have provided, the following something like what you are after:
use strict; use warnings; my @paras = ( {a => 10, b => 3, e => 15, k => 1}, {a => 8, d => 4, e => 17, r => 5}, ); my $paraNum = 1; for my $para (@paras) { my @letters = sort {$b->[0] <=> $a->[0]} map {[$para->{$_}, $_]} keys %$para; print "Paragraph $paraNum:\n"; print join ("\n", map {"$_->[1]: $_->[0]"} @letters), "\n"; ++$paraNum; }
Prints:
Paragraph 1: e: 15 a: 10 b: 3 k: 1 Paragraph 2: e: 17 a: 8 r: 5 d: 4
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Sorting a array of hashes
by Anonymous Monk on Nov 14, 2007 at 03:37 UTC |