Re: Read - testing for EOF
Re: Read - testing for EOF
- Subject: Re: Read - testing for EOF
- From: Axel Luttgens <email@hidden>
- Date: Tue, 20 Jan 2004 10:06:37 +0100
Chap Harrison wrote:
How do you know when you've reached EOF when reading a file
sequentially, record by record?? (using Standard Additions read)
Reading when at EOF seems to *usually* throw an error, which can be
caught in a try... on error block, but it doesn't seem to be
dependable. Sometimes it returns the final record twice before
throwing the error; sometimes it returns a null record infinitely.
You are right (well, I think so ;-) ) when thinking that something along
those lines should do the job:
repeat
try
set chunk to read R until myDelim
[ process read chunk here ]
on error
[ do some cleanup here if needed ]
exit repeat
end try
end repeat
But yes, while preparing my reply yesterday, I encountered behaviors
similar to the ones you are describing.
As it appeared very elusive, I wasn't sure if it was me or AppleScript,
so I wanted to investigate a bit further; but I wouldn't leave you alone...
Here is a case I can reproduce:
1. write sequence "aaaLbbbLcccSdddLeeeLfffLS" to
a file (with no ending CR or LF), where L in fact
is ASCII number 163 and S is ASCII number 164.
2. run a script similar to the above, where myDelim
is set to ASCII character 163
Result: an endless loop, with the last pseudo-L read ad infinitum.
Should you have them at hand, could you post minimal sample data/code
producing similar effects?
Thanks,
Chap
PS - Am I missing a vital documentation resource? Please let me know
- I can't believe I'm having such a hard time finding answers to these
simple questions myself. :-(
Some times ago, I posted this link:
http://manuals.info.apple.com/Apple_Support_Area/Manuals/software/0305098AASADDGENG.PDF
Very old, but still a reference the same way the ASLG is.
(as far as the file-related commands are concerned, this was before the
"using delimiter" argument and before unicode...)
HTH,
Axel
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.