Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

hoh - print in the inserted order

by perlthirst (Scribe)
on Mar 02, 2009 at 08:33 UTC ( [id://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.

Replies are listed 'Best First'.
Re: hoh - print in the inserted order
by GrandFather (Saint) 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.

    sas
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
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-26 05:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found