From: Ben Giddings Date: 2003-10-02T02:15:27+09:00 Subject: Re: Array and hash iteration questions Robert Klemme wrote: > cases = Hash.new {|h,k| h[k] = [0, 0]} Ah. I couldn't remember how to use the block form properly. I'm actually going to use: cases = Hash.new {|hash, key| hash[key] = Hash.new(0)} Because it will make some of the later stuff more clear like cases[case]['Number'] += 1 cases[case]['Errors'] += 1 if arr[OFFSET] =~ /Error/ > cases.sort.each do |ca, counter| > printf "%10s: %4d", ca, counter[0] > printf " %4d", counter[1] if counter[1] > 0 > print "\n" > end Aha, I just assumed hash didn't have a sort method, because the concept of a "sorted hash" seemed meaningless, but since it actually returns an array containing [key, value] pairs, that's perfect! Thanks Robert Ben