Re: Reading a file into a "sequence"

new topic     » goto parent     » topic index » view thread      » older message » newer message

John F Dutcher wrote:
> 
> You guys do a heck of a job...
> The sub routine is a nice piece of work....
> This is returned in "ex.err"  when called with the input below &
> the code lines below:
> 
>     "sequence lengths are not the same (4 != 0)"
> 
> This seems to refer to line (12) of "CSV_to_Sequence(object pText)"
> 
> 
> }}}
<eucode>
> sequence Fields 
>    	
>    fn=open("tml_extract.txt","r")
>    if fn < 1 then
>   	puts(1, "Unable to open the disk file\n")
>         abort(fn)
>    else 
>      while 1 do 
>         Fields = CSV_to_Sequence( gets(fn))
>         if Fields = {} then exit
>         else  .....
>            -- etc. etc.
> </eucode>
{{{

> 
> The first record in "tml_extract.txt" is:
> (and does seem to contain (4) "fields")
> 
> "%HDR","EXTRACT","11/17/2004 02:23:10 AM","UNIVERSITY OF ROCHESTER MEDICAL
> CENTER"

This is one of those areas that Euphoria is a very unintuitive.  With the
'IF' statement, you can only use the relationship operators (= != < > ...)
with atoms and never with sequences. What happens is that when you do

  if Seq = A then

the phrase 'Seq = A' actually creates a new (temporary) sequence containing
ones and zeros, and passes that temporary sequence to the IF, but an 
IF statement must have the form ...
   
  if <atom-expression> then ...

I know, it is pretty stupid, and everyone trips over this at least once,
but that's what RDS believes is a good thing to do. 

Anyhow, to fix your problem do either this  ...

  if length(Fields) = 0 then exit end if (*don't forget the 'end if')

or

  if equal(Fields, {}) then exit end if (*don't forget the 'end if')

-- 
Derek Parnell
Melbourne, Australia

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu