Thanks all for the reply! This worked wonderfully. I also tried reverse() and switching the a/b around to get a reverse sorted order with equal success.
Thanks again! --Chuck > -----Original Message----- > From: Nikola Janceski [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, February 06, 2002 1:28 PM > To: 'Tomasi, Chuck'; '[EMAIL PROTECTED]' > Subject: RE: Sorting an array of hashes > > > @sorted = sort { > $a->{ID} <=> $b->{ID} ## remember that $a and $b > become the element > of the array > ## so if it's a reference to a hash use a dereferencer '->' or > # $$a{ID} <=> $$b{ID} > # will work too! > } @AoH; > > foreach $item (@sorted){ > print $item->{ID}, "\n"; > } > > -----Original Message----- > From: Tomasi, Chuck [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, February 06, 2002 2:18 PM > To: '[EMAIL PROTECTED]' > Subject: Sorting an array of hashes > > > Does anyone have any clever ideas for sorting an array of > hashes based on > a key such as an ID number? > > Example: > > @AoH = ( > { ID => 10101, UserID => 1041, Status => 2 }, > { ID => 10541, UserID => 1211, Status => 1 }, > { ID => 10111, UserID => 1211, Status => 2 }, > { ID => 10721, UserID => 1198, Status => 1 } > ); > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > -------------------------------------------------------------- > -------------- > -------------------- > The views and opinions expressed in this email message are > the sender's > own, and do not necessarily represent the views and opinions of Summit > Systems Inc. > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]