On Wed, 6 Feb 2002, Tomasi, Chuck wrote: > 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 } > );
This is quite similar to the question posed earlier about sorting on an element of an anonymous array in a hash: my @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 } ); my @ID = (); foreach(@AoH) { push @ID, $_->{ID} } my @result = sort {$a <=> $b} @ID; foreach(@result) { print "$_\n"; } -- Brett http://www.chapelperilous.net/ ------------------------------------------------------------------------ "Seed me, Seymour" -- a random number generator meets the big green mother from outer space -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]