From: John Pritchard-williams Date: 2008-08-08T06:59:13+09:00 Subject: Most compact command for associate array 'totalling'? Ok - in 'awk' you can do this: (Where 'array' is empty initially) array[]++ For instance: array["abc"]++; => a["abc"]=1 array["abc"]++; => a["abc']=2 ... Which is really useful for tallying up a complete column of varying values from a text file where you don't know in advance the what may appear in a column etc... In Ruby, I have worked out a similar the equivalent to be: (with a Hash now...) a={}; a["abc"]=a["abc"].to_i+1; But I"m sure there is a shorter way ? Better trick available here? As an aside to 'to_i' is to turn the 'nil' into zero: is this safe to assume this? Thanks - sorry if this is stupid question.... John -- Posted via http://www.ruby-forum.com/.