[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

compare 2 "arrays"

chris

11/5/2007 6:05:00 PM

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

2 Answers

Johan Veenstra

11/5/2007 8:34:00 PM

0

Note: parts of this message were removed by the gateway to make it a legal Usenet post.

On 11/5/07, Christian <ozric@web.de> 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)

chris

11/5/2007 9:36:00 PM

0

On 5 Nov., 21:33, johan.veens...@gmail.com wrote:
> Note: parts of this message were removed by the gateway to make it a legal Usenet post.
>
> On 11/5/07, Christian <oz...@web.de> 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)


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

thanks christian