rsiedl has asked for the wisdom of the Perl Monks concerning the following question:
Can anyone help me out?#!/usr/bin/perl use strict; use warnings; my %item1 = ( "item" => 1, "name" => "smith, john", "age" => 25, "height" => 1.80 ); my %item2 = ( "item" => 2, "name" => "jones, bob", "age" => 26, "height" => 1.70 ); my %item3 = ( "item" => 3, "name" => "arrang, eliee", "age" => 27, "height" => 1.75 ); my %hash; $hash{1} = { %item1 }; $hash{2} = { %item2 }; $hash{3} = { %item3 }; my $orderby = "name"; foreach my $id (sort { $hash{$b}{$orderby} <=> $hash{$a}{$orderby} } k +eys %hash) { print "$hash{$id}{'item'} - $hash{$id}{$orderby}\n"; } # end-foreach exit;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: numerical and non numerical sorts
by Zaxo (Archbishop) on Oct 06, 2005 at 12:22 UTC | |
|
Re: numerical and non numerical sorts
by Roy Johnson (Monsignor) on Oct 06, 2005 at 12:40 UTC | |
|
Re: numerical and non numerical sorts
by Fang (Pilgrim) on Oct 06, 2005 at 12:26 UTC | |
|
Re: numerical and non numerical sorts
by Skeeve (Parson) on Oct 06, 2005 at 12:47 UTC | |
|
Re: numerical and non numerical sorts
by Perl Mouse (Chaplain) on Oct 06, 2005 at 12:26 UTC | |
|
Re: numerical and non numerical sorts
by Anonymous Monk on Oct 07, 2005 at 10:51 UTC |