Hi --

On Mon, 25 Nov 2002, ahoward wrote:

> On 24 Nov 2002, Robert Cowham wrote:
>
> [snip]
> R> h = {}
> R> f = File.open("fred.ini", "r")
> R> f.each_line{|l| s = l.chomp.split("="); h[s[0]] = s[1]}
> R> f.close
> [snip]
>
> (IO.readlines 'foo').each {|line|  (hash ||= {}).store *(line.chomp.split '=')}

You need to have the 'hash' variable be in scope already when you
start accumulating, because otherwise...

  irb(main):006:0> (IO.readlines 'conf.txt').each {|line|
  (hash ||= {}).store *(line.chomp.split '='); p hash}
  {"key1"=>"value1"}
  {"key2"=>"value2"}

...you get a new 'hash' each time through :-)  (and nothing
visible once the iteration finishes)


David

-- 
David Alan Black
home: dblack / candle.superlink.net
work: blackdav / shu.edu
Web:  http://pirate.shu.edu/~blackdav