我想获得每个组的条目数,但它似乎给了我错误的答案。每个组中都有可能重复的元素。我得到的结果没有意义。我究竟做错了什么?
my %hash;
while(<>)
{
chomp($_);
if(/(\d+)\t(\d+)/)
{
my $group = $1;
my $element = $2;
$hash{$group}{$element}=1;
}
}
foreach my $curr(keys %hash)
{
my $numElementsInCurr = keys %{$hash{$curr}};
print "$curr\t$numElementsInCurr\n";
}