From: Robert Klemme Date: 2008-05-14T20:06:57+09:00 Subject: Re: array diff 2008/5/13 James Dechiaro : > if SumArray.include?(row[1])did the trick...thanks adam! > > > Adam Shelly wrote: >> On 5/12/08, James Dechiaro wrote: >>> the problem i'm running into is when i try to open back the csv1 and >>> compare the SumArray against it in order to get the entire line (not >>> just the element). It instead prints all the lines, even the ones not >>> contained in the array. >>> >>> So it looks as though the .eql? module is not working correctly. >>> >> There are a few potential problems with this line: >> records.collect do |row| row[1].eql?(SumArray) >> >> First, I think you need an 'if'. Otherwise you are calling eql? but >> not using the result. Second, it looks like you are comparing a >> single field with the >> whole SumArray. They will never be equal. You probably want something >> like >> if SumArray.include?(row[1]) You might also want to consider using Set or Hash for more efficient lookups. The way I would probably do it is this: define a record type that covers all the relevant information (easily done with Struct). Then read the file to test against (csv2 I believe) and convert records to the record type which you then add to the Set / Hash. Then read the second file line by line, convert it and print it if it is not contained in the Set / Hash. That way you do not need to keep both files in memory and the Set / Hash lookups are much faster than Array based lookups. Kind regards robert -- use.inject do |as, often| as.you_can - without end