in reply to iterate/traverse Two Hashes at once

While it would be possible to loop over two (or more) hashes of equal size at the same time (see example below), the question is why? The 'order' of the key-value pairs of the hashes will not directly correspond to each other in any meaningful way (as shown below) unless, IIRC, the keys of the pairs and the insertion order of the pairs are identical for the hashes – in which case, why not just use a single hash with an array of two (or more) values per key?

>perl -wMstrict -le "my %ha = qw(ka1 va1 ka2 va2 ka3 va3); my %hb = qw(bk1 bv1 bk2 bv2 bk3 bv3); while (my ($ka, $va) = each %ha and my ($kb, $vb) = each %hb ) { print qq{a: $ka => $va b: $kb => $vb} } " a: ka1 => va1 b: bk3 => bv3 a: ka3 => va3 b: bk2 => bv2 a: ka2 => va2 b: bk1 => bv1
Maybe you want to extract the sets of keys from two hashes, order the sets relative to each other in some way, and then process the key-value pairs?