#!/usr/bin/perl

use warnings;

####################################################################
#
#	wordcount.pl
#
#	9/17/02 (Jeff Ondich)
#
#	Collects a list of words and their frequencies from standard
#	input and prints the list sorted by word and then sorted
#	by frequency.
#	
####################################################################

my %wordhash;

# Collect the data.
while( <> )
{
	@words = split /\W+/;
	for $w (@words)
	{
		$w = lc $w;
		$wordhash{$w}++;
	}
}

# Print the alphabetized list.
foreach $w (sort keys %wordhash) 
{
	print "$w\t$wordhash{$w}\n";
}

print "\n\n===========================\n\n";

# Print the list sorted by frequency.
foreach $w (sort { $wordhash{$b} <=> $wordhash{$a} } keys %wordhash)
{
	print "$w\t$wordhash{$w}\n";
}
