From: Stuart Clarke Date: 2008-12-18T23:49:41+09:00 Subject: Re: Using ruby hash on array Sorry for not being clear. I am actually parsing data from Windows event logs and as a result the data is held in structured fields. Earlier in my program I load the contents of a number of event logs into an array and then ready the data using structs for example to read the ID number - event.event_id more complicated for descriptions - event.description[/Name:\t(.+?)\r\n/, 1]} So what I would like to do is read my event log array and check for specific event ID's (if event.event_id == 100). If the if statement finds the ID 100 it reads name from event.description. Everything mention thus far is working correctly. When this is complete I then want to do a count on how many times each name occurs e.g. bob = 2, sue = 12. My thoughts were to load the event.description[/name:/] into a hash and then do a count on each name in the hash and print it out. Does this make more sense?? Louis-Philippe wrote: > I don't know if I got you right... > If a is the identifier, then your data structure could be something > like: > > hash = { 'data A' => ['data B', 'data C', 'data D', 'data E', 'data F'], > 'data A' => ['data B', 'data C', 'data D', 'data E', 'data F'], > 'data A' => ['data B', 'data C', 'data D', 'data E', 'data F'] } > > where you could access a data A like hash['data A'] or with if > hash.has_key?('data A') > and data F with hash['data A'][4]. > > 2008/12/17 Stuart Clarke -- Posted via http://www.ruby-forum.com/.