From: Ilan Berci Date: 2007-12-05T00:18:06+09:00 Subject: Re: hash Johnathan Smith wrote: > File.open('reference.txt').each do |line| > if line =~ /^tag:/i > $linecount += 1 > end > end > puts $linecount > # try something like this: linecount = 0 results = [] hash = {} File.open('reference.txt').each do |line| m = line.match /^(\w+):\s*([\w+,\s]+)$/ unless m results << hash unless hash.empty? hash = {} else linecount += 1 hash[m[1]] = m[2].chomp end end -- Posted via http://www.ruby-forum.com/.