Re: Reading a file into a "sequence"

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

John F Dutcher wrote:
> 
> The code below reads a text file (a few lines are shown) into a Euphoria 
> sequence as shown. Because the file is a series of  quoted strings, 
> delimited by commas....I guess I expected I would have a "sequence" 
> ready made in "line" after each read....and that I could refer to each
> quoted string in line as line[1] or line[2] or line[3] etc.
> 
> Not so it seems...but line[1..41] does give the 1st (41) characters in 
> each line when displayed.
> 
> Yet, the tests for "%HDR" and "%TRL" fail when using line[1..4].
> 
> Something more is needed to allow referring to each quoted string in the
> file as a member of a sequence....again as in line[1] or line[2] ??
> 
> *************************************
> }}}
<eucode>
> sequence line 	
>    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 
>         line = gets(fn)
>         if atom(line) then exit
>         else  
>           if equal(line[1..4], "%HDR") or equal(line[1..4], "%TRL") then
>           	 a = 0
>           else
>              puts(1, line[1..41] & "\n")
>           end if
>         end if
>      end while
>    end if     
> </eucode>
{{{

> 
> *********************   file sampling  ************
> "%HDR","EXTRACT","11/17/2004 02:23:10 AM","UNIVERSITY OF ROCHESTER MEDICAL
> CENTER"
>
> "%DTL","000061474714","000001821707","BARNES","CHARLES","","03/31/2001","03/20/2001","03/20/2001","000001819.00","000000000.00","11/07/2004","E3R","000001819.00","A1O","
>   ","86115","YJP115341192","     ","10549",,,,,,,"86","EMG ","C"," "
>
> "%DTL","000079336343","000002008157","FRANCIS","DALE","","11/13/2004","09/19/2002","09/19/2002","000002198.00","000000000.00","11/01/2004","09","000000408.00","A1O","
>   ","50102","132288832A","     ","02262",,,,,,,"50","BMT ","C"," "
>
> "%DTL","000079336343","000002008157","FRANCIS","DALE","","11/13/2004","09/19/2002","09/19/2002","000002198.00","000000000.00","11/03/2004","17","000000408.00","A1O","
>   ","50102","132288832A","     ","02262",,,,,,,"50","BMT ","C"," "


The first for characters of the first line are  ...

   "%HD

you need to either break up each line into fields or do this ...

   if equal(line[1..6], "\"%HDR\"") or equal(line[1..6], "\"%TRL\"") then
 
-- 
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