From: James Edward Gray II Date: 2009-09-14T05:10:00+09:00 Subject: Re: FasterCSV.foreach loop On Sep 13, 2009, at 2:28 PM, Dot Baiki wrote: > Hello community, Hello. > This is the way my CSV file looks like: > > id,name,valid_time,date > 1,baiki,5:00,9/10/2009 > 1,baiki,1:45,9/14/2009 > 2,lee,6:00,9/8/2009 > 3,fatou,9:15,8/14/2008 > 3,fatou,10:15,8/13/2008 > 2,lee,6:00,9/7/2009 > 2,lee,6:55,9/6/2009 > 2,lee,6:00,9/8/2009 > 1,baiki,5:00,9/11/2009 > 1,baiki,4:00,9/12/2009 > 1,baiki,2:00,9/13/2009 > 3,fatou,12:15,8/13/2008 > 3,fatou,12:15,8/18/2008 Is this file large? It looks like you may eventually just want all of the data in it. If that's the case, and it's not too big to suck the whole thing into memory, it may be easier to work with that way. For example: data = FCSV.table(input_file) p data[:id].uniq # these are the uniq ID's > But I ran into a problem - ok, I admit it: SEVERAL PROBLEMS :-). > until employee_id.empty? > FasterCSV.foreach(input_file, :headers => true) do |row| > if row[0] == employee_id[0] > puts "value: #{row}" > next > end > employee_id.shift > end > end > But I get just the records of id 1, 1, 3. > > What am I missing? You remove an ID from employee_id after reading each line of your CSV data. I think you meant to do something more like this: employee_id.each do |id| FCSV.foreach(input_file, :headers => true) do |row| puts "value: #{row}" if row["id"] == id end end Hope that helps. James Edward Gray II