in reply to Preserving order for nested hashes using Tie::IxHash
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).tie (my %data, 'Tie::IxHash');
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.tie(my %data, 'Tie::IxHash'); while ( ... ) { # add info to %data if ( <working in a second tier> ) { if ( ! exists $data{$top_level_key) ) { $data{$top_level_key} = {}; tie ( %{$data{$top_level_key}}, 'Tie::IxHash' ); } ... } ... }
UPDATE
The following suggestion already exists, as Borisz points out below.
End 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.
|
|---|