I have some data scrubbing to do, and to divide and conquer the problem, I decided to fix the easy things first, so that I can work in peace on the trickier stuff.

In essence, I have a hash of hashes that represent the count of attributes seen for a collection of things. Sometimes I see the same attribute more than once, sometimes I see many attributes once, and any combination in between.

Most of the things, though, have one attribute, seen once. I therefore wanted to go throught the hash and put them to one side, and put what remains on the other. The trouble is, that solitary attribute has an abitrary name, so I can't just see if it exists. After futzing around a while and getting nowhere fast and more and more complicated, the following suddenly popped out at me.

Note that the $h{key}{subkey} stuff below is actually coming from something like:

while( <> ) { chomp; my( $key, $subkey ) = split; $h{$key}{$subkey}++; }

(It's the $h{$c}{(keys %{$h{$c}})[0]} == 1 bit that pleases me).

#! /usr/bin/perl -w

use strict;

my %h;

# two different subkeys

# one subkey

# one subkey seen more than once

for my $c( keys %h ) {
    if( scalar keys %{$h{$c}} == 1 and $h{$c}{(keys %{$h{$c}})[0]} == 
+1 ) {
        print "$c has a ${\(keys %{$h{$c}})[0]}\n";
    else {
        print "$c is complicated\n";