reading from a file

Alex Tweedly alex at tweedly.net
Sun Jun 12 08:21:19 EDT 2005


John Ridge wrote:

>I need to read from a text file until I hit EOF - but in the meantime I want
>to process each of the chunks I'm reading (separated by delimiters).
>
>It seemed obvious and natural to start off, after opening the file,
>   
>       repeat until EOF
>       read from file xxx until <delimiter>
> ...process next chunk...
>       end repeat
>
>But, alas, this runs forever - it doesn't encounter EOF, although I was
>careful to "close" the file when I wrote it out. I can't find anything in
>the docs that explains why it doesn't work. Should it?
>
>Apologies if the answer is just too obvious!
>John
>  
>
EOF is simply a constant for "an end of file character"

One way you can do what you want  (there are bound to be others :-) is ...

   open file tName for read
    repeat forever
       read from file tName until cr
       if the result = "eof" then exit repeat
       put it & cr after msg    -- to check it is being read
  end repeat
  put "done" & cr after msg    -- to check we exit OK

... note "result" can be set to other values if there is an error - 
depending on circumstances, you may want to check for that happening.

-- 
Alex Tweedly       http://www.tweedly.net



-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.323 / Virus Database: 267.6.8 - Release Date: 11/06/2005



More information about the use-livecode mailing list