5% assure discount from here only

Showing posts with label hash order. Show all posts
Showing posts with label hash order. Show all posts

Tuesday, January 25, 2011

(12) How to make a hash remember, the order put elements into it?

Solution :

Ordinarily Perl does not guarantee the order of items in a hash to be in any predictable order.
If this is important you can easily add a "keep-in-order" behavior to a particular hash by "tying"
that hash to the Tie::IxHash module. Of course you must first use the module, then, once you tie
your hash to this module, the module will automatically add the desired behavio

Solution :

Use the Tie::IxHash from CPAN.

use Tie::IxHash;

tie my %myhash, 'Tie::IxHash';