Sometimes, a good solution is to maintain both an hash and an array in order to have the best of two worlds. The array keeps track of the right order and the hash makes it possible to access quickly to the real data. In this case, your main data structure can be either the hash (possibly HoH, or whatever) and the array (possibly AoH, or whatever), and the other data structure just acts as an auxiliary data structure to get the other property that you need. Writing a subroutine that maintains both structures synchronized is no big deal, perhaps just 3 or 4 code lines if you need insertions, possibly a couple of more if you also need to manage deletions.
All this logics could also be encapsulated in objects, but this might be a bit of an overkill if what you described is all what you need. (OK, yes, I have been discovered, I am somewhat reluctant to OOP for simple problems; to me it is often over-engineering, I tend to prefer the KISS principle. I recently rewrote a 1000+line Java program into a Perl program having less than 75 lines of code. I do not see why I should shoot a bullet in my foot trying to do it the Java way. But this is just my own personal prejudiced opinion, do as you wish.)
In reply to Re: keep hash insert oder, hash inside hash
by Laurent_R
in thread keep hash insert oder, hash inside hash
by aboboras
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |