From: daz Date: 2005-12-06T04:22:34+09:00 Subject: Re: Labelled text file parsing... William James wrote: > > table = {} > ARGF.each { |line| line.strip! > next if line == "" > fields = line.split( /: +/ ) > if fields.size == 1 > $fruit = fields.first > table[$fruit] = {} > else > table[$fruit][fields.first] = fields.last > end > } > OK, I saw your $fruit rationale after removing $ ;) Here's a variation: #--------------------------------------------------- table = {}; fruit = nil IO.foreach('fruit.txt') do |line| k,v = line.strip.split(/: +/) k or next v and table[fruit][k] = v or table[fruit=k] = {} end #--------------------------------------------------- daz