On Thu, Oct 13, 2011 at 1:49 PM, Khalid Rajput <khalidaslam / hotmail.com> wr=
ote:
> =A0 I am working on a small project which requires two 2-dimensional
> arrays to be produced from CSV files and then compared on some values
> and then producing a third array with as the result which then can be
> stored as CSV file.
>
> Example :
> =A0 Name, qtymin, qtymax,qtycurrent, qtyorder
> [["Atorva", 20, 50, 33, =A010],["lipit", 10, ....]]
>
> 2nd file :
> =A0 =A0Name, =A0qtyusedtoday
> [["Atorva", =A015],["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

--=20
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/