Friday, January 4, 2008

ordering hash

use Tie::IxHash;
tie %HASH, "Tie::IxHash";
# manipulate %HASH
@keys = keys %HASH; # @keys is in insertion order

#Tie::InsertOrderHash does not allow you to change values in your hash and keep the original ordering. Thus, as mentioned above, updating the days in February will cause February to now appear after December when listing the keys.
#If you want to be able to change values without changing the ordering then Tie::IxHash may be a better option.

No comments: