From: Ryan Mckenzie Date: 2011-07-22T07:32:02+09:00 Subject: Re: Splitting strings Ok, so far at the minute then I have included the counter hash so I have the following: def count_frequency the_file='D:/Rails/projects/data.txt' h = Hash.new words = Hash.new f = File.open(the_file, "r") counts = Hash.new 0 if.each do |line| phrase = line.scan /\w+/ limit = phrase.length - 1 0.upto limit do |start| start.upto limit do |stop| puts phrase[start..stop].join(' ') end end counts.sort_by {|w,c| -c}.each do |w,c| printf "%6d %s\n", c, w end end end Would the counter hash with the key go underneath the 'puts' in the loop so that it records each step? At the minute it still just outputs the new strings without the ordering. Many thanks, Ryan -- Posted via http://www.ruby-forum.com/.