# Compare 2 "arrays"

**URL:** <https://www.ruby-forum.com/t/compare-2-arrays/119282>\
**Category:** Ruby\
**Created:** [November 5, 2007, 7:06pm UTC](https://www.ruby-forum.com/t/compare-2-arrays/119282 "2007-11-05T19:06:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![caefer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e36b37/32.png) [@caefer](https://www.ruby-forum.com/u/caefer)\
**Post date:** [November 5, 2007, 7:06pm UTC](https://www.ruby-forum.com/t/compare-2-arrays/119282/1 "2007-11-05T19:06:08Z")

</div>

Hello,

sorry i’m a beginner with ruby and hanging on  
a problem comparing two arrays?

Have anybody an advice what’s wrong in my logic, beacuse printing of k  
and row2[“id”] like  
p “#{k} = #{row2[“id”]}” works!?

many thanks ,Christian

rows=0  
ngs=Array.new

# some thousand id’s

FCSV.foreach("#{path}#{part1}",:headers =\>true ,:col\_sep =\> “\t”) do |  
row|  
ngs.push(row[“id”])  
end

# a lot of millions

FCSV.foreach("#{path}#{part2}",:headers =\>true ,:col\_sep =\> “\t”) do |  
row2|  
ngs.each do |k|  
if k == row2[“id”]  
p row2  
end  
end  
end

mp\_hash.rb:36: undefined local variable or method `found' for main:Object (NameError) from cmp_hash.rb:34:in`each’  
from cmp\_hash.rb:34  
from c:/ruby/lib/ruby/gems/1.8/gems/fastercsv-1.2.0/lib/faster\_csv.rb:  
1429:in `each' from c:/ruby/lib/ruby/gems/1.8/gems/fastercsv-1.2.0/lib/faster_csv.rb: 990:in`foreach’  
from c:/ruby/lib/ruby/gems/1.8/gems/fastercsv-1.2.0/lib/faster\_csv.rb:  
1162:in `open' from c:/ruby/lib/ruby/gems/1.8/gems/fastercsv-1.2.0/lib/faster_csv.rb: 989:in`foreach’  
from cmp\_hash.rb:33

---

<div class="post-metadata">

**Author:** ![caefer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e36b37/32.png) [@caefer](https://www.ruby-forum.com/u/caefer)\
**Post date:** [November 5, 2007, 9:49pm UTC](https://www.ruby-forum.com/t/compare-2-arrays/119282/2 "2007-11-05T21:49:36Z")

</div>

On 11/5/07, Christian [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> mp\_hash.rb:36: undefined local variable or method `found’ for

On line 36 of the source file mp\_hash.rb is something called ‘found’,  
but it is not defined.  
The same happen with the follwing very short program:

test=found

ruby -w test.rb

test.rb:1: undefined local variable or method ‘found’ for main:Object  
(NameError)

---

<div class="post-metadata">

**Author:** ![caefer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e36b37/32.png) [@caefer](https://www.ruby-forum.com/u/caefer)\
**Post date:** [November 5, 2007, 10:55pm UTC](https://www.ruby-forum.com/t/compare-2-arrays/119282/3 "2007-11-05T22:55:11Z")

</div>

On 5 Nov., 21:33, removed\_email\_address@domain.invalid wrote:

> test=found
> 
> ruby -w test.rb
> 
> test.rb:1: undefined local variable or method ‘found’ for main:Object  
> (NameError)

arrgh a classical example -  
to not see the forest for the trees

thanks christian
