From: Brian Candler Date: 2007-02-06T23:36:53+09:00 Subject: Re: Parse csv similar file On Tue, Feb 06, 2007 at 11:32:27PM +0900, Rebhan, Gilbert wrote: > questions= > what kind of collection is the best ? is an array sufficient ? Depends what you want to do with it. If you want to be able to find an entry E123456 quickly, then you'd use a hash. If you want to keep only the first/last entry for a particular key (as it seems you do), using a hash speeds things up here too. > right now i have = > > efas=Array.new > File.open("mycsvfile", "r").each do |line| > if line =~ /(\w+.?);(\w+);(\w+);(\w+);(\w+);(\w+)/ > > efas<<$3.to_s<<',' unless efas.include?($3.to_s) > > end > end > puts efas.to_s.chop Try: efas = Hash.new ... efas[$3] = [$1,$2,$4,$5,$6] unless efas.has_key?($3) ... puts efas.inspect > Are there better ways as regular expressions ? You could look at String#split instead HTH, Brian.