Dec 16, 2000, 11:10 AM
Post #4 of 5
There is still the problem of improper use of seek(). Paraphrasing the documentation, here's how to use the function.
seek(FH, OFFSET, WHENCE)
FH is a filehandle
OFFSET is a number of bytes (it can be negative), relative to WHENCE
WHENCE is either 0 (for start of file), 1 (for current offset), or 2 (for end of file)
Thus, to seek to the end of the file, one would do seek(FH, 0, 2). To go back one byte from where you are now, you would do seek(FH, -1, 1).
You must realize that line numbers are meaningless pieces of data to anything but a human. "Line" number is specifically misleading -- it is actually a "record" number to the computer. Records are, by default, streams of characters that end in a newline. And because records needn't be of the same length, there's no way to jump to a specific record in constant time.
If someone would create an OS where files where kept as linked lists of strings, then things would be far easier. Jumping to a specific record would still take O(n) time, but insertion and deletion and modification would be far more efficient.
Jeff "japhy" Pinyan -- accomplished hacker, teacher, lecturer, and author