reading from a file

Jon jbondy at sover.net
Sun Jun 12 13:33:31 EDT 2005


Alex recommended "read from file tName until cr".  Is this the prefered 
approach, or should it be "until return"?  I'm not sure which is the 
most portable approach.

:)

Jon


Alex Tweedly wrote:

> 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.
>


More information about the use-livecode mailing list