Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

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
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (3)
As of 2017-11-18 02:57 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (277 votes). Check out past polls.