From: Robert Klemme Date: 2008-12-19T07:27:08+09:00 Subject: Re: Using ruby hash on array On 18.12.2008 20:12, Stuart Clarke wrote: > Sorry I was getting to replying to you then got called off in a hurry. I > do not understand some of the code you have used as I am relatively new > to Ruby. Can you briefly outline the code, it would be greatly > appreciated. I define a class holding the data you want to parse from the file via Struct. I then also define a parse method on that class that will take a line (basically a String) and parse it into a new data structure. You will likely have to change these as field names like "a" and "b" are not really telling and also you might want to do the parsing differently. Then I initialize a Hash with default value 0. This is the value returned for keys that are not present in the Hash. Then the code reads from all input files (ARGF) named on the command line (or stdin if there is no name), parses each line and increments the counter for the entry. Finally the Hash is sorted by key and key value pairs are printed. Cheers robert -- remember.guy do |as, often| as.you_can - without end