printf "id\tscore\n";
for my $app (keys %records) {
my $apprecordref = $records{$app};
my %apprecord = %$apprecordref;
my $idlen = scalar(@{$apprecord{"id"}});
for ($i = 0; $i < $idlen; $i++) {
printf "%d\t%d\n", $apprecord{"id"}[$i], $apprecord{"score"}[$i];
}
}
id score
0 4
1 5
2 6
3 7
4 8
Или вот другой способ сделать это, который я думаю, немного проще:
my $app = "info";
my %records;
for (my $i = 0; $i < 5; $i++)
{
# $records{$app} is a list of hashes, e.g.
# $records{info}[0]{id}
push @{$records{$app}}, {id=>$i, score=>$i+4};
}
printf "id\tscore\n";
for my $app (keys %records) {
my @apprecords = @{$records{$app}};
for my $apprecordref (@apprecords) {
my %apprecord = %$apprecordref;
printf "%d\t%d\n", $apprecord{"id"}, $apprecord{"score"};
}
}