# OK, so, I've not written to Q&A files, but I did only get a little
# while to have a go at it.
# 
#!/usr/bin/perl

#$source = '/home/steve/words/allwords.txt';
#$source = '/home/steve/words/soed.txt';
$source = '/usr/dict/words';

open(WORDS,$source) || die "in pain $!";

while (<WORDS>) {

  # I wonder which way round is the most efficient and which is the
  # most readbale order for the next three lines.

  chomp;

  next if /[^a-z]/i;

  my $word = lc($normc = $_); # set normal case

  ##

  for ($i=0,$s = substr($word,$i,4); 
       $i < length($word)-3; 
       $s = substr($word,++$i,4)) {
  
    if ($done{$s}) { # if we've seen this one before
      
      # remove entries that already thought they were uniq

      delete $uniq{$s} if exists $uniq{$s};

    } else {

      # assume, for now, we're uniq and set done

      $uniq{$s} = $normc;
      $done{$s} = 1; # here for clarity
    }
  }
}

for $s (sort keys %uniq) {

  print "$s $uniq{$s}\n";
}
