Here are four very simple/clean syntaxes to choose from:
-
{ my %h = ( x=>5, y=>8 );
while ( my ($r,$s) = each %h ) {
...
}
}
-
for ({ x=>5, y=>8 }) {
while ( my ($r,$s) = each %$_ ) {
...
}
}
-
for (paired( x=>5, y=>8 )) {
my ($r,$s) = @$_;
...
}
where paired is defined as
sub paired {
my @pairs;
push @pairs, [ shift, shift ] while @_;
return @pairs;
}
-
paired {
my ($r,$s) = @_;
...
} ( x=>5, y=>8 );
where paired is defined as
sub paired(&@) {
my $cb = shift;
my @rv;
push @rv, $cb->(shift, shift) while @_;
return @rv;
}