Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I've the following code:
I'm thinking if there's a way to sort the array by 'score' to produce the output:my @data = ( { name => 'john', score => '70' }, { name => 'peter', score => '90' }, { name => 'dan', score => '50' }, ); foreach my $href (@data) { print "$href->{'name'}\t$href->{'score'}\n"; } # ouptput john 70 peter 90 dan 50
Is there a way to do it?peter 90 john 70 dan 50
Thanks :)
2005-12-17 Retitled by GrandFather to fix spelling of references (to aid searching)
Original title: 'Sorting array of hash refereces'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sorting array of hash references
by bobf (Monsignor) on Dec 17, 2005 at 05:30 UTC | |
|
Re: Sorting array of hash references
by davido (Cardinal) on Dec 17, 2005 at 05:25 UTC | |
|
Re: Sorting array of hash references
by l.frankline (Hermit) on Dec 17, 2005 at 07:56 UTC | |
|
Re: Sorting array of hash references
by Anonymous Monk on Dec 17, 2005 at 05:55 UTC |