Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
coldfingertips,
It seems that people often want to use a hash so they can have key lookup functionality but also want the hash to come out in a specific order as well. If you want the hash to come out in the order it was created, than Tie::IxHash is probably for you ( and if you need speed look at Tie::Hash::Indexed which is written in XS ). Do not use these modules if you need your hash sorted though. While it does provide 3 methods to resort the hash (user provided key list or ASCIIBetically by keys/values), it does not provide any mechanism for retaining auto-sorting new keys/values. This is one of the reasons I wrote Tie::Hash::Sorted. It allows the user to define their own sort routine (even using lexicals the module wouldn't normally see) as well as numerous optimization options to choose from. Your code would look something like:Modifying the hash does not require any additional work to keep the sorted order. Cheers - L~R In reply to Re: Twice the pleasure of sorting a hash
by Limbic~Region
|
|