[Tutor] File Access

Nick Lunt nick at javacat.f2s.com
Tue Apr 6 13:43:15 EDT 2004


On Mon, 5 Apr 2004 17:53:53 -0400
"R. Alan Monroe" <amonroe at columbus.rr.com> wrote:
 
> If you were desperate you could look at the source code for gnu's
> version of the good old tail command.

Ha, I aint that desperate. The last thing I want to do is get my old C books out. I never really got my head round pointers and I don't wanna try again now ;)

 
> One thing you could try is reading successively larger and larger
> chunks from the end of the file, like powers of two (1 byte, 2 bytes,
> 4 bytes, 8 bytes, 16 bytes, etc.) until you grab a chunk that has a \n
> in it, then work forward from there. Haven't personally tried this,
> though.

I guess that would work, but it seems a bit of a fudge doesn't it ?

I could also pad the lines out before they are written to the file, then when I seek to the end of the file I would know how many bytes to rewind to get to the start of the line.

So it's pad the lines so each line is x bytes, which again seems like a fudge. Or use 'for line in file' which would be slow on a file with many lines.

Ho hum, I still don't know which is best.

Cheers
Nick.






More information about the Tutor mailing list