----- Original Message ----- From: "Octavian Rasnita" <[EMAIL PROTECTED]>
To: <beginners@perl.org>
Sent: Monday, May 09, 2005 2:32 PM
Subject: sorting a hash
Hi,
I have a reference to a hash of hashes, something like:
my $ref = { c => { name => 'a', age => 20, }, b => { name => 'e', age => 24, }, a => { name => 'z', age => 14, }, };
I want to sort the persons with the codes 'a', 'b', and 'c' by their name,
and print something like:
"a has the name z and has 14 years". ... then the next person in order...
foreach my $key (sort (keys %$ref)){ print "$key => $ref->{$key}{name} is $ref->{$key}{age}\n"; }
Thank you.
Teddy
Teddy
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>