Newbie Q why doesn't this NEXT work

the data: -17780 51697-62657 51697-62651 date: 2453507 << good data
error in data file:
-17737,147401-93780
147401-93780,147401-93780,12/28/2004
ruby code:
cppewq=[]
CSV.open(“neat.txt”,“r”) do |row|
hh=row[3]
h1=row[1]
h2=row[2]
h3=row[0]
next if hh=nil || h1=nil || h2=nil || h3=nil
g=ParseDate::parsedate(row[3])[0…2]
j=Date.new(g[0],g[1],g[2])
puts 'the data: ‘+"#{row[0].to_i.to_s}"+’ ‘+row[1]+’ ‘+row[2]+’ date:
'+"#{j.jd.to_s}"
cppewq<<[row[0].to_i,row[1],row[2],j] if j!=nil && row[1]!=nil &&
row[2]!=nil
end

TypeError: can’t dup NilClass
from c:/ruby182/lib/ruby/1.8/date/format.rb:236:in dup' from c:/ruby182/lib/ruby/1.8/date/format.rb:236:in_parse’
from c:/ruby182/lib/ruby/1.8/ParseDate.rb:9:in parsedate' from (irb):25 from (irb):24:inopen_reader’
from c:/ruby182/lib/ruby/1.8/csv.rb:311:in parse' from c:/ruby182/lib/ruby/1.8/csv.rb:531:ineach’
from c:/ruby182/lib/ruby/1.8/csv.rb:531:in parse' from c:/ruby182/lib/ruby/1.8/csv.rb:311:inopen_reader’
from c:/ruby182/lib/ruby/1.8/csv.rb:85:in `open’
from (irb):24
from (null):0

dave rose [email protected] writes:

h3=row[0]
next if hh=nil || h1=nil || h2=nil || h3=nil

Comparison is ==, not = in Ruby. Here you would assign nil.

Tom

dave rose wrote:

g=ParseDate::parsedate(row[3])[0…2]

TypeError: can’t dup NilClass

Looks like row[3] is nil.

I always like to display the actual objects/values when
developing/debugging to ensure that the state/data matches my
expectaions…

Cheers

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs