[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

newbie Q why doesn't this NEXT work

dave rose

7/7/2006 4:02:00 PM

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

--
Posted via http://www.ruby-....

2 Answers

Tom Rauchenwald

7/7/2006 4:17:00 PM

0

dave rose <bitdoger2@yahoo.com> writes:

> 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

Chris Hulan

7/7/2006 6:45:00 PM

0

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

--
Posted via http://www.ruby-....