// $Id: wordfreq.ici,v 1.0 2003/01/03 12:23:00 dada Exp $
// http://dada.perl.it/shootout
//
// contributed by Tim Long
static counts = struct();
static
tolower(s)
{
s = explode(s);
forall (c, i in s)
{
if (c >= 'A' && c <= 'Z')
s[i] += 'a' - 'A';
}
return implode(s);
}
while (l = getline())
{
forall (w in smash(l, #\w+#, "\\&"))
{
if (w ~ #[A-Z]#)
w = tolower(w);
if (counts[w] == NULL)
counts[w] = 1;
else
++counts[w];
}
}
out = array();
forall (c, w in counts)
push(out, sprintf("%7d\t%s\n", c, w));
sort(out, [func(a, b){return a > b ? -1 : a < b;}]);
put(implode(out));