From: "David A. Black" Date: 2008-12-18T10:25:54+09:00 Subject: Re: Your word frequency calculator? Hi -- On Wed, 17 Dec 2008, C. Pohjanraito wrote: > Hi! I am studying various texts and code. > > Word frequency calculator is one basic tool. I find it an interesting, > elementary problem to solve. > > I found this word frequency analyser by William James: > > freq = Hash.new(0) > loop { > data = (STDIN.read(4095) or break) + (STDIN.gets || "") > for word in data.downcase!.tr!('^a-z',' ').split That's a dangerous technique, because str.downcase! is nil if there's no change to the string, and nil.tr! will blow up. David -- David A. Black / Ruby Power and Light, LLC Ruby/Rails consulting & training: http://www.rubypal.com Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2)