From: Intransition Date: 2011-11-05T12:53:32+09:00 Subject: Re: Ruby Challenge ------=_Part_1559_12898378.1320465209170 Content-Type: multipart/alternative; boundary="----=_Part_1560_21416042.1320465209170" ------=_Part_1560_21416042.1320465209170 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Why does this sound like a school assignment? file = 'sample.txt' freq = Hash.new{|h,k| h[k] = 0} File.read(file).scan(/\w+/) do |w| freq[w] += 1 end freq.each do |w,c| puts "#{c} #{w}" end Untested. ------=_Part_1560_21416042.1320465209170 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit Why does this sound like a school assignment?

    file = 'sample.txt'
    freq = Hash.new{|h,k| h[k] = 0}
    File.read(file).scan(/\w+/) do |w|
      freq[w] += 1
    end
    freq.each do |w,c|
      puts "#{c} #{w}"
    end

Untested.

------=_Part_1560_21416042.1320465209170-- ------=_Part_1559_12898378.1320465209170--