DÅa Tuesday 28 September 2004 11:42 Gunnar Hjalmarsson napÃsal: > Octavian Rasnita wrote: > > I have a hash that have multiple sub hashes and I want to sort it > > by a sub key. > > > > For example, I have: > > > > $comp{$code}{$year}{profit}. > > > > And I want to sort the $code values after the value of the "profit" > > key. > > > > Is this possible directly, or I will need to create another hash > > for doing this type of sort? > > You don't need another hash. > > perldoc -f sort > perldoc -q "sort a hash" > > my @codes = sort { > $comp{$a}{$year}{profit} > <=> > $comp{$b}{$year}{profit} > } keys %comp;
my @codes = sort {$a <=> $b} keys %comp; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>