我试图使用列表/数组
对哈希进行排序my $hash = { cta => '01340031810312074443',
ttr => '001',fil => '0000',
ref => '0000',
mef => '0000000000000060000',
mch => '0000000000000000000',
nli => '00000000',
tdi => 'V',
ndi => '006126952',
tdip => 'V',
ndip => '006126952',
};
@order = qw(cta ttr fil ref mef mch nli tdi ndi tdip ndip);
我们知道Perl不会以散列方式保存订单,但我需要按此顺序打印。我怎么能这样做?
由于
答案 0 :(得分:7)
如果您只想打印值而不是键,则还可以使用哈希切片:
use feature 'say';
say join "\t", @hash{@order};
答案 1 :(得分:2)
for my $key (@order) {
print $key . ": " . $hash->{$key} . "\n";
}
答案 2 :(得分:1)
试试这个:
for (@order) {
print $_, " => ", $hash->{$_}, "\n";
}