Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

hoh - print in the inserted order

by perlthirst (Scribe)
on Mar 02, 2009 at 08:33 UTC ( #747411=perlquestion: print w/replies, xml ) Need Help??
perlthirst has asked for the wisdom of the Perl Monks concerning the following question:


I have hash of hash.

I will insert the data (key and value) in a hash whenever required.

At last while printing, it has to print the hash key and values, in the same order that i have inserted.

If any module is available to achieve this kindly advice.

Replies are listed 'Best First'.
Re: hoh - print in the inserted order
by GrandFather (Sage) on Mar 02, 2009 at 08:40 UTC
Re: hoh - print in the inserted order
by andreas1234567 (Vicar) on Mar 02, 2009 at 11:35 UTC
Re: hoh - print in the inserted order
by sasdrtx (Friar) on Mar 02, 2009 at 10:54 UTC

    Push the keys onto an array, and use it to drive the print loop.

Re: hoh - print in the inserted order
by CountZero (Bishop) on Mar 02, 2009 at 20:57 UTC
    There is one caveat when using Tie::IxHash: although order is preserved when adding new key - value pairs, the keys must be unique. If you add a duplicate key, the value is changed, but the order of the original key is retained. This may or may not be what you want.


    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://747411]
Approved by GrandFather
[hippo]: Is the NVIDIA driver problem still a thing?
[zentara]: See problems with Nvidia and Linus Torvalds
[choroba]: that's 2012
[zentara]: I just acquired a computer with the card type, and wondered if it was best to stick with the open-source code or use NVIDIA's proprietary code

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (11)
As of 2017-05-26 13:53 GMT
Find Nodes?
    Voting Booth?