#!/usr/bin/perl
##################################################################
# Count words, the short version.  (2 lines of code!)
# Usage:  ./count2 bskrv10.txt
# Version 1.0, Jim Mahoney, 10/22/2002.  (See also countWords.pl)
##################################################################

map { $h{lc($_)}++ if $_ } split /[^a-zA-Z\-_]/ while (<>);
printf(" %-30s %10d \n",$_,$h{$_}) for (sort {$h{$b}<=>$h{$a}} keys %h)[0..49];

#
# Here's what those two $@!!& lines are saying.
#
# Read the first line of perl from right to left.  It says:
#   While there's a line of text which can be read in,
#   Split that line into words, dividing it at characters that are 
#      not in ( a-z A-Z - _ )
#   Apply this function to each of those words:
#      If it isn't the empty string, convert to lowercase, 
#      then increment the hash table "h" using the word as the key.
#
# The second line of perl is also a loop.  Again from right to left:
#    Find the keys in the hash named "h", and sort them by the hash values 
#       (i.e. word counts).
#    For each of the first 50 words in that list,
#       print out the word followed it's value in the hash table.
#
# So there you are.
#
