From: Louis-Philippe Date: 2008-12-18T07:40:46+09:00 Subject: Re: Using ruby hash on array ------=_Part_13418_28160634.1229554113291 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline 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 > I would like to process some data from an array and using hash to > perform a count on one aspect of the data in the array. The array holds > lines of similarly formatted data like so > > 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 > > data A is the identifier of each row full of data, data F contains a lot > of data which requires a regular expression which is passed to a method > for example: > > "#{data F[/Name:\t(.+?)\r\n/, 1]}" > > I am stuck writing the hash section of the code. The alogorithm is > > if data A == 100 > load data F reg expression into hash > end > count data F to determine the number of each name extracted by the > regular expression > print bob 6, sue 12, tim 1 > > I hope this makes sense and many thanks in advance > -- > Posted via http://www.ruby-forum.com/. > > ------=_Part_13418_28160634.1229554113291--