Alex Young
2/16/2007 2:28:00 PM
Peter Bailey wrote:
> Alex Young wrote:
>> Peter Bailey wrote:
>>>> @cost_centers = Hash.new(0)
>>>> def add_to_cost_centers(center_key, amount)
>>>> @cost_centers[center_key] += amount
>>>> end
>>>>
>>>> Hope this helps,
>> <snip>
>>> @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
>> What happens when you put:
>>
>> p @cost_centers
>>
>> after this?
>
> I get a half pyramid of data, like this, all the way down for about 150
> entries. What I want, of course, is a single column of unique cost
> center entries, with page count totals for each. But, at least I'm
> getting something. Thanks for your help, Alex. I'll keep you abreast of
> any progress.
> {"ADAM00"=>8}
> {"CBCD00"=>8, "ADAM00"=>8}
> {"CBCD00"=>8, "EDDG00"=>8, "ADAM00"=>8}
> {"CBCD00"=>8, "EDDG00"=>8, "JOSH00"=>4, "ADAM00"=>8}
> {"CBCD00"=>8, "EDDG00"=>8, "JOSH00"=>4, "ADAM00"=>8, "HCCG00"=>4} . . .
Eh? You should get a single hash... What I'm trying to get at is
rather than try to access the data inside the loop, it should be exactly
what you're looking for after the loop's finished. You want the last
line of the pyramid, I think.
--
Alex