Hi Tiana,

if you run the following version of your code you will easily see what is
happening:

REBOL []

blk: read/lines %test.dat       

print "blk contains:"
foreach string blk [print mold string]
print "end blk contains"

while [not empty? blk]
[
print ["=====>" newline
mold to-block first blk newline
"<====="
]

    d1:  second (to-block first blk) 
    d1: parse d1 "-"
    d1: to-date d1/1    
    print d1    
    blk: next blk 
    print blk   
    either not empty? blk [print "not empty"][print "empty"]
]

In short what happens is that when you read/lines your file, empty lines in
the file are contained in blk as emtpy strings:

[""]

When you check 
empty? blk

and blk is [""] then blk is not empty of course (it contains an element
which is an empty string). But the string is empty and therefore there is
no second element in the string. So 

    d1:  second (to-block first blk) 

fails. to-block first blk will return an empty block [] and there is no
second element in the empty block.

It's safer to use pick (to-block first blk) 2 instead of second. The
advantage is that pick series index returns none when there is nothing to
pick instead of generating an error. 

  So you can say:

    if d1: pick (to-block first blk) 2 [
      d1: parse d1 "-"
      d1: to-date d1/1    
      print d1    
    ]
    blk: next blk 
    print blk   
    either not empty? blk [print "not empty"][print "empty"]

and only attempt to process d1 if it is not none.

Hope this helps,


;- Elan >> [: - )]

Reply via email to