in reply to Moose reading big file line by line

You want the nextLine method to buffer your input. The buffer should contain a block of lines from the file. The method returns the next line from the buffer. If the buffer is empty, refill it with the next block from the file. This is fairly straight forward if all lines are exactly the same length. If not, I doubt that the benefit is worth the effort to get it right.
Bill
  • Comment on Re: Moose reading big file line by line

Replies are listed 'Best First'.
Re^2: Moose reading big file line by line
by CountZero (Bishop) on Apr 27, 2015 at 16:02 UTC
    Why not simply leave the buffering to the OS? Not every <readline> will necessarily cause a physical disk access. Unless the lines are very long, there is a good chance that many lines will be read at once and made available to you without again going to the disk.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

    My blog: Imperial Deltronics