title: Perl: multidimensional hash
body: <p>suppose I have the following data </p>
  
  <p><strong>cluster1:d(A),f(C)s,(A)</strong></p>
  
  <p><strong>cluster2:r(D),h(D),f(A)</strong></p>
  
  <p>I want this out put </p>
  
  <p>output:</p>
  
  <pre><code>   cluster1:A-&gt;2
     cluster1:C-&gt;1
     cluster2:D-&gt;2
     cluster2:A-&gt;1
  </code></pre>
  
  <p>here is my try,but it is not correct , the part that I am trying to count characters has a problem that I cant fix
  the code is a part of very big code ,and I want exactly multidimensional hash</p>
  
  <pre><code>use strict;
  use Data::Dumper;
   my %count;
  while (&lt;DATA&gt;) {
      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-&gt;$count{$name}{$subject}\n";
      }
  }
  </code></pre>
  
  <p><strong>DATA</strong></p>
  
  <p>cluster1:d(A),f(C)s,(A)</p>
  
  <p>cluster2:r(D),h(D),f(A)</p>