Utiliser la fonction each :
while(my($key,$value) = each(%hash))
{
# Faire quelque chose avec $key et $value
}
La fonctions keys retourne un tableau des clefs d'une table de hachage, de cette façon, il est possible de trier un hashage selon la clef :
#!/usr/bin/perl
use strict;
my %h;
$h{'f'} = "toto";
$h{'a'} = "tata";
$h{'z'} = "titi";
my @tab = sort{$a cmp $b}(keys(%h));
foreach my $k (@tab)
{
print $h{$k}."\n";
}
Plus d'informations dans la documentation de Perl :