Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] composite key hash

Expand Messages
  • Jenda Krynicky
    From: matt_johnsson ... foreach my $item (keys %myhash) { my @subkeys = split $;, $item; print $subkeys[0], $subkeys[1],
    Message 1 of 3 , Sep 2, 2003
    • 0 Attachment
      From: "matt_johnsson" <matt_johnsson@...>
      > I'm currently using a composite key hash to gather counts
      > of certain combinations of data.
      > Bogus sample data:
      > BOB,M,C
      > TED,T,D
      > BOB,M,C
      > TED,D,D
      > BOB,M,C
      > so I go through my data and want to end up with:
      > BOB,M,C 3
      > TED,T,D 1
      > TED,D,D 1
      > I ended up using a composite key hash like
      > if ( defined ( $myhash{$key1,$key2,$key3 }))
      > { $myhash{$key1,$key2,$key3}++; }
      > else
      > { $myhash{$key1,$key2,$key3} = 1; }
      > works fine, but when I want to print out the resulting hash, keys and
      > values, how do I split out my composite keys? I keep getting all the
      > keys concatinated like: BOBMC, which could be B OBM C or BO B MC or

      foreach my $item (keys %myhash) {
      my @subkeys = split $;, $item;
      print "$subkeys[0], $subkeys[1], $subkeys[2]: $myhash{$item}\n"
      }

      See the description of $; in
      perldoc perlvar

      Jenda


      ===== Jenda@... === http://Jenda.Krynicky.cz =====
      When it comes to wine, women and song, wizards are allowed
      to get drunk and croon as much as they like.
      -- Terry Pratchett in Sourcery
    Your message has been successfully submitted and would be delivered to recipients shortly.