in reply to Having Access to a file two times

Do you really need to read the TSV file twice in order to process your data? For large TSV files it might be faster to read the file only once line-by-line and perform the two operations - currently distributed over two different while-loops - within the same loop.

On the other hand, if processing time doesn't matter and code keeps cleaner, seek might be the better option.

Replies are listed 'Best First'.
Re^2: Having Access to a file two times
by dsheroh (Monsignor) on Sep 21, 2008 at 17:54 UTC
    Yeah, that was basically my first thought, too. If the file is small enough to easily fit in memory, read it all into an array and then walk the array for each operation. If it's too big for that, then read through it once doing both operations as you go. Either way, you'll get better performance out of it, since disk access is almost always the slowest operation.