Tie::IxHash
doesn't have an Each
method, but you can use Perl's each
function on the tied hash:
use Tie::IxHash;
my $t = tie my %hash, 'Tie::IxHash';
@hash{qw/a b c d e/} = (1, 2, 3, 4, 5);
# using the tied hash
while (my ($key, $val) = each %hash) {
print "$key => $val\n";
}
# using the OO interface (interchangeably)
foreach my $key ($t->Keys) {
my $val = $t->FETCH($key);
print "$key => $val\n";
}
Note that $t->Values($key)
won't work. This method expects an index not a key. This will work:
foreach (0 .. $t->Length - 1) {
my ($key, $val) = ($t->Keys($_), $t->Values($_));
...
}