Keep It Simple, Stupid | |
PerlMonks |
Re: Preserving order for nested hashes using Tie::IxHashby shemp (Deacon) |
on Aug 19, 2005 at 21:16 UTC ( [id://485308]=note: print w/replies, xml ) | Need Help?? |
You need to tie each of the hashes that you want order preserved in. When you do:
That ties the hash %data as a Tie::IxHash, but never does anything about the values in %data. (keep in mind that ALL hash values are scalars). You'll need something like this: Without knowing how you're creating these nested hashes, i can't give better insight, but hopefully my little framework will express the idea to you.
UPDATE If you wanted to (if it suits your needs), you could cook up a more complicated version of Tie::IxHash (call it something else - like Tie::IxHash::MultiLevel), that checks if values being added to the hash are HASHREF's, and if they are, then tie them also. I don't particularly recommend this approach, because it could bite you later on. It will be automatically recursive down the levels though, because if a second tier hashref is tied as a Tie::IxHash::MultiLevel, then it will do checking on its values too. I use the most powerful debugger available: print!
In Section
Seekers of Perl Wisdom
|
|