Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

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:

hi

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.

Comment on hoh - print in the inserted order
Re: hoh - print in the inserted order
by GrandFather (Cardinal) on Mar 02, 2009 at 08:40 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.

    sas
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 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.

    CountZero

    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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://747411]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2014-07-26 12:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (176 votes), past polls