newbie Q why doesn't this NEXT work

D

dave rose

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:in `open_reader'
from c:/ruby182/lib/ruby/1.8/csv.rb:311:in `parse'
from c:/ruby182/lib/ruby/1.8/csv.rb:531:in `each'
from c:/ruby182/lib/ruby/1.8/csv.rb:531:in `parse'
from c:/ruby182/lib/ruby/1.8/csv.rb:311:in `open_reader'
from c:/ruby182/lib/ruby/1.8/csv.rb:85:in `open'
from (irb):24
from (null):0
 
T

Tom Rauchenwald

dave rose said:
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

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

Tom
 
C

Chris Hulan

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top