View Single Post
Old 03-10-2005, 04:51 AM  
Zester
Confirmed User
 
Zester's Avatar
 
Industry Role:
Join Date: Jul 2003
Posts: 5,344
how to (really) sort a hash by key in Perl

lets I have a hash:

%hash=(
'2004' => "red",
'2006' => "blue",
'2005' => "green"
);

how do I sort it by key? i don't want to print it out sorted, only sort it

using this:
@keys = sort keys %hash;

will NOT work, because @keys now contain only the keys
why is it so fucking hard to get this:

%hash=(
'2004' => "red",
'2005' => "green",
'2006' => "blue"
);
__________________
* Mainstream ? $65 per sale
* new male contraception

Last edited by Zester; 03-10-2005 at 04:53 AM..
Zester is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote