From: Khalid Rajput Date: 2011-10-15T07:11:11+09:00 Subject: Re: Reading CSV files into arrays and then comparing Robert Klemme wrote in post #1026417: > On Thu, Oct 13, 2011 at 1:49 PM, Khalid Rajput > wrote: >> Name, qtyusedtoday >> [["Atorva", 15],["lipit",4...]] >> >> The idea is that to read one row in the first file and then try to find >> a match the same item in the second file by reading whole file. In case >> of match/no match produce a row in third array which eventually could be >> given out as a separate csv file. >> >> Thanks in advance > > For that Arrays are not well suited since the lookup is slow. Rather > you would be doing something like this > > 1. read second file into a Hash using appropriate key (e.g. an Array > of the key fields). > 2. read the first file via CSV.foreach, for each record > 2.1 do the lookup in the Hash from step 1 > 2.2 write out the resulting CSV line, either to stdout or to a file > > Kind regards > > robert Thanks robert, I have recently started working in ruby and am a noobie. I had only read that ruby community is very helping in books but i really finds it true. I'll try this approach and will reply how it goes Thanks once again -- Posted via http://www.ruby-forum.com/.