Perl-Sensitive Sunglasses | |
PerlMonks |
(dkubb) Re: (2) Idiom for looping thru key/value pairsby dkubb (Deacon) |
on May 27, 2001 at 07:19 UTC ( [id://83567]=note: print w/replies, xml ) | Need Help?? |
The CPAN module Tie::DxHash will allow you to make a hash that retains the order the keys were entered, and allows duplicate keys as well. Here's a short example to show you how simple it's usage is:
An interesting thing to note is that in the assignment to %hash the duplicate keys are not clobbered. You can then iterate over this hash using while/each or a foreach/keys, and the elements will be returned in the order they were inserted into the hash.
In Section
Seekers of Perl Wisdom
|
|