From: Peter Bailey Date: 2007-02-16T04:47:37+09:00 Subject: Re: Iterating through 2 fields for one hash, or array. Alex Young wrote: > Peter Bailey wrote: >> DER000 128 >> Cost Center Page Count >> TMUS00 96 >> ER0000 42 >> DER000 192 > I don't know the syntax for getting the data out of KirbyBase, but the > trick I usually use for this sort of thing is a hash with a default > value. Something like: > > @cost_centers = Hash.new(0) > def add_to_cost_centers(center_key, amount) > @cost_centers[center_key] += amount > end > > Hope this helps, Thanks, Alex. I'm sorry. I didn't include any KirbyBase lingo originally. Here's a portion of my script, with your code in it. "x" is each row of the table. With the code below, I am getting each cost center and its respective page count, but, I'm still not getting discrete cost centers nor page count totals. I don't want any repeats with the cost centers and I want a total page count for each cost center. @cost_centers = Hash.new(0) def add_to_cost_centers(center_key, amount) @cost_centers[center_key] += amount end testcount_tbl.select(:costcenter, :pagecount).each do |x| add_to_cost_centers(x.costcenter, x.pagecount) puts x end -- Posted via http://www.ruby-forum.com/.