in reply to Re^3: Reading files, skipping very long lines...
in thread Reading files, skipping very long lines...

How do you know if you've skipped over a newline?

Be well,
rir

  • Comment on Re^4: Reading files, skipping very long lines...

Replies are listed 'Best First'.
Re^5: Reading files, skipping very long lines...
by Roy Johnson (Monsignor) on Sep 30, 2005 at 16:42 UTC
    If you're reading each line as soon as it is appended to the file, there won't be a newline.

    But if there's a chance that another line will follow more quickly than your seek gets there, you could always read backwards $MAX bytes to see if there's a newline.


    Caution: Contents may have been coded under pressure.
      If you're reading each line as soon as it is appended to the file, there won't be a newline.

      But we are not reading the lines, we are just seeking to the EOF. How do we guarantee that we are fast enough? (I am not sure if the system or just the program is overwhelmed by size of lines.)

      Let MAX be seven. N is a newline. The following data arrives.

      1...N.........9........N.2N...............f....x15

      We capture the line containing 1. We start on the next line but give up before we get to character 9; so we seek on the file and end up at x15; then we read back to about f. How can we ever be sure that we are not missing one or more lines in the area of 2?

      I feel confident there is a race condition but it has been more than a decade since I've seeked on any file in any language.

      Be well,
      rir

        But we are not reading the lines, we are just seeking to the EOF.

        It may be the same thing. The OP wanted to "wait for the next line", which suggests that the lines come in one at a time, and with some delay between them.


        Caution: Contents may have been coded under pressure.