XP is just a number | |
PerlMonks |
Re: Trouble with Tie::IxHashby bart (Canon) |
on May 23, 2006 at 18:49 UTC ( [id://551218]=note: print w/replies, xml ) | Need Help?? |
You're not creating the nested hash in the proper order, as you're using anonymous hashes as values somewhere, which are intrinsically unordered. And then, it's too late to fix it.
First off, take a look at a module our co-monk japhy wrote: Tie::Autotie. It'll automatically tie deeper hashes also. If you then would assign the values one by one, it would already work:
You might not like the required syntax — though for reading from a data file, it'd probably work fine. I'm thinking of an alternative to anonymous hashes: tied hash references. I don't know if any module already implements them, but you can build them by hand: In that case, you should be able to write (including the above sub): which looks acceptable to me... no? update n.b. You don't need to use Tie::Autotie if you use the latter suggestion, make sure to replace every anonymous hash with a call to ixhash(), and never rely on autovivification. p.s. You can use Tie::Hash::Indexed as a plug-in replacement for Tie::IxHash. The former is written in XS, the latter in Pure Perl, so it should be faster. I haven't run a benchmark, though.
In Section
Seekers of Perl Wisdom
|
|