From: Keith Tom Date: 2007-03-31T02:15:21+09:00 Subject: Re: newbie, hash or 2dArry Zac Elston wrote: > I'm lost or just tired from guessing. > > I need to make an hash I can call by hostname as the key and some random > amount of data after that as the values. now a hash works great for 1 > to 1 maps (h[serverX] ==> result) but I need > h[serverX][query|result|time] > > so how would I write a hash that would give me access to > > in: > h[host_to_query]["query"]] = @query > h[host_to_query]["result"]] = queryhost(host_to_query,@query) > > out: > for h.each |host| puts h[[host]["result"]] > > thanks > > zaq > > Hey Zac, Would a nested hash do the trick? hash = { :host1 => { :query => @query, :result => queryhost(...), :time => time} } then for output, you'd do something like for hash.each_value do |value| puts value[:result] end Hopefully that does the trick, Keith