假设我有以下数据
集群1:d(A),f(C)s,(A)
集群2:r(D),h(D),f(A)
我想要这个
输出:
cluster1:A->2
cluster1:C->1
cluster2:D->2
cluster2:A->1
这是我的尝试,但它不正确,我试图计算字符的部分有一个问题,我无法修复代码是非常大的代码的一部分,我想要多维哈希
use strict;
use Data::Dumper;
my %count;
while (<DATA>) {
my %HoH;
my ( $cluster, $ch ) = split (/:/,$_);
$HoH{$cluster}={split /[()]+/,$ch};
for my $clust ( keys %HoH ) {
for my $character ( keys %{ $HoH{$clust} } ) {
$count{$clust}{$HoH{$clust}{$character}}++;
}
}
}
print Dumper(\%count);
foreach my $name (sort keys %count) {
foreach my $subject (keys %{$count{$name}}) {
print "$name:$subject->$count{$name}{$subject}\n";
}
}
数据
集群1:d(A),f(C)s,(A)
集群2:r(D),h(D),f(A)