Tie::SortHash is a Perl module to keep hashes in a sorted order.
SYNOPSIS
use Tie::SortHash;
my %people = (
'John Doe' => 33,
'Jane Doe' => 29,
'Jim Smith' => 15,
);
my $sortblock = q(
my $c = (split /s+/, $a)[1];
my $d = (split /s+/, $b)[1];
$c cmp $d
||
$hash{$a} $hash{$b}
);
tie %people, 'Tie::SortHash', \%people, $sortblock;
foreach my $name ( keys %people ) {
print $name . " is " . $people{$name} . " years old.
";
}
# This output will always be
Jane Doe is 29 years old.
John Doe is 33 years old.
Jim Smith is 15 years old.
This module is a designed to be a light weight hash sorting mechanism. It is often frustrating to have a hash return elements in a random order, such as when using the keys(), values() and each() functions, or simply when iterating over them.
Product's homepage
Requirements:
· Perl