Monday, January 3, 2011

Perl: Create a hash and preserve the add-order

#Tie::IxHash
#ordered associative arrays for Perl
#to display same order in the hash

use Tie::IxHash;
tie (%hash, Tie::IxHash);
$hash{'one'} = "un";
$hash{'two'} = "deux";
$hash{'three'} = "trois";
while (($k, $v) = each %hash) {
    print "$k\t$v\n";
}

No comments: