如何打印2个哈希插入键?

时间:2012-10-17 22:01:53

标签: perl

拜托,我正在通过以下方式初始化2个哈希:

$hash1{$key} = -9;
$hash2{$key} = -9;

然后我按照键的顺序得到数组@order:

my @order1 = sort {$a cmp $b} keys(%hash1);
my @order2 = sort {$a cmp $b} keys(%hash2);

然后我想打印插入密钥的这两个数组。示例:1º散列的1º键,2º散列的1º键,依此类推。

print(join("\t", @order1, @order2) . "\n"); #this will print the entire hash1 first and     then the hash 2

请问我该怎么做?

1 个答案:

答案 0 :(得分:3)

use List::MoreUtils qw( pairwise );
say join "\t", pairwise { $a, $b } @order1, @order2;