Hi Tiana,

when your file has an empty last line, pointing at this line
your block is not yet empty, because it is pointing at "".
now try

to-block ""
== []

which has no second element. Thus the error.

One possible solution is:

blk: read/lines %test.dat
while [
   all [
       not empty? blk
       not none? 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"]
]

'pick does not raise an error, if the refereneced element does
not exist, but returns 'none.
'all returns 'true, if all of it's elemets return 'true


hope this helps,

regards,

Ingo


Those were the words of [EMAIL PROTECTED]:
> Hi, Andrew,
> Thanks for your reply. I don't think it is the problem of a simple while loop. I
> attached my script and input file in this msg:
> 
> blk: read/lines %test.dat       
> while [not empty? blk]
> [
>     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"]
> ]
> 
> test.dat:
> 
> 21-Feb-2000    { 2000/02/01-00:20  -  2000/02/08-21:48 }    76    29    
> 20-Feb-2000    { 2000/02/02-00:20  -  2000/02/08-21:48 }    76    29    
> 19-Feb-2000    { 2000/02/03-00:20  -  2000/02/08-21:48 }    76    29    
> 
> 
> This test.dat file is generated by machine. The weird thing is if I open the
> file and clear its tail, the script worked fine. But if I added an empty newline
> at the end of file, it won't work. 
> ** Script Error: Out of range or past end.
> ** Where: d1: second (to-block first blk) 
> 
> When rebol execute 
> 
> either not empty? blk [print "not empty"][print "empty"]
> 
> it always prints 'not empty' even the content of blk printed is blank.
> 
> I'm so frustrated about this. Can u help me out?
> 
> Thanks a million.
> 
> Tiana
> 

--  _     .                                _
ingo@)|_ /|  _| _  <We ARE all ONE   www._|_o _   _ ._ _  
www./_|_) |o(_|(/_  We ARE all FREE> ingo@| |(_|o(_)| (_| 
http://www.2b1.de/Rebol/                     ._|      ._|

Reply via email to