-----Original Message-----
From: Chris Mortimore [mailto:[EMAIL PROTECTED]
Sent: Thursday, August 05, 2004 5:19 PM
To: [EMAIL PROTECTED]
Subject: Sorting an array of hashes
I want to sort an AoH. Not each hash by its keys, but the array by the
value of one of the keys in each hash. I know how to sort a simple
array. I know how to sort a hash by the keys. Could someone kindly point
me to the documentation on sorting arrays of hashes?
Thank you!
Chris.
Hope this gives you some ideas...
#! /usr/local/bin/perl @AoH=({office=>C,employees=>500},{office=>A,
employees=>30}); $ndx=0; foreach (@AoH){
print "$_->{office}, $ndx \n";
$IofH{$_->{office}} = $ndx++;
}
foreach (sort keys %IofH){
print "$_, $IofH{$_}\n";
%nH = %{$AoH[$IofH{$_}]};
print "Office $_ has employees $nH{employees}\n";
}
jwm
Thank you John. How to build the index and relate it back to the
original array of hashes is exactly what I was trying to figure out!
Gratefully, Chris.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>