我编写了以下例程,遍历哈希 0 - 7 并打印出每个中特定键的值。我需要在每个哈希中获取 'b4' 的值。
我想取消(0..7),当有不同数量的哈希时,使用更智能的东西。例如,有时只有 2 个,或者可能有 160 个。
my $out = decode_json $client->responseContent();
#print "\nOutput is :\n\n" . Dumper $out;
for my $slice (0..7) {
my $out = $out->{data}[$slice]{b4};
print " $out \n";
}
数据结构如下:
DB<1> x $out
0 HASH(0x125fb5e0)
'data' => ARRAY(0x1260d760)
0 HASH(0x121765d0)
'b1' => '21'
'b2' => '22'
'b3' => '23'
'b4' => '24'
'b5' => '25'
'b6' => '26'
'b7' => '27'
1 HASH(0x125fb650)
'b1' => '21'
'b2' => '22'
'b3' => '23'
'b4' => '24'
'b5' => '25'
'b6' => '26'
'b7' => '27'
2 HASH(0x1236b960)
'b1' => '21'
'b2' => '22'
'b3' => '23'
'b4' => '24'
'b5' => '25'
'b6' => '26'
'b7' => '27'
3 HASH(0x12177030)
'b1' => '21'
'b2' => '22'
'b3' => '23'
'b4' => '24'
'b5' => '25'
'b6' => '26'
'b7' => '27'
4 HASH(0x1260da00)
'b1' => '21'
'b2' => '22'
'b3' => '23'
'b4' => '24'
'b5' => '25'
'b6' => '26'
'b7' => '27'