#This calculates statistics for lines sung in "The Ballad of Michigan J". #leonardr 6/30/1999 %abbrevs = ( "A" => "All", "F" => "Fred", "G" => "Grep", "M" => "Michigan J.", "N" => "Narrator", "B" => "Boss", "Z" => "Zcat", ); while(<>) { if (/^\w: /) { \$last = substr(\$_,0,1); \$times{\$last}++; }elsif (/ /) { \$times{\$last}++; } if (/Snickers/) { \$snickers{\$last}++; } if (/Snickers bar/) { \$snickers_bar{\$last}++; } if (/Snickers bar, Snickers bar/) { \$snickers_bar_snickers_bar{\$last}++; } } print "Statistical analysis of \"The Ballad of Michigan J.\"\n"; print "---------------------------------------------------\n\n"; print "As you can see, this data conclusively proves that \"Ballad\" was\n"; print "written by ALIENS, as no human could possibly be this obsessed\n"; print "with the phrase \"Snickers bar, Snickers bar\"\n\n"; print "Total lines:\n"; foreach \$a (sort keys %abbrevs) { print "\$abbrevs{\$a}: \$times{\$a}\n"; } print "\n"; print "\"Snickers\" lines:\n"; foreach \$a (sort keys %abbrevs) { print "\$abbrevs{\$a}: \$snickers{\$a} (". percent(\$snickers{\$a}/\$times{\$a}). " of total)\n" if \$snickers{\$a}; } print "\n"; print "\"Snickers bar\" lines:\n"; foreach \$a (sort keys %abbrevs) { print "\$abbrevs{\$a}: \$snickers_bar{\$a} (". percent(\$snickers_bar{\$a}/\$times{\$a}) ." of total)\n" if \$snickers_bar{\$a}; } print "\n"; print "\"Snickers bar, Snickers bar\" lines:\n"; foreach \$a (sort keys %abbrevs) { print "\$abbrevs{\$a}: \$snickers_bar_snickers_bar{\$a} (". percent(\$snickers_bar_snickers_bar{\$a}/\$times{\$a}) ." of total)\n" if \$snickers_bar_snickers_bar{\$a}; } print "\n"; sub percent { (\$a) = @_; \$a *= 10000; \$a = int(\$a); \$a /= 100; return \$a."%"; }