# count frequency on line lengths (from stdin)
# - call from pipe

# - if we run through words.pl first, then we can get the frequency of words

use strict;

# ---------- ---------- ---------- ----------

# open file, get all text
my @theFile = <STDIN>;

# do frequency breakdown
my %theFreq;
my $theMaxLen = 0;

foreach my $theLine (@theFile) {
  chomp($theLine);

  my $theLen = length($theLine);

  $theFreq{$theLen}++;
  if ($theMaxLen < $theLen) {
    $theMaxLen = $theLen;
  }
}

# output frequency breakdown
for (my $i = 1; $i <= $theMaxLen; $i++) {
  print("$i, $theFreq{$i}\n");
}
