in reply to Re^3: How does the while works in case of Filehandle when reading a gigantic file in Perl
in thread How does the while works in case of Filehandle when reading a gigantic file in Perl

Actually sundialsvc4 is close to the truth (but not quite there yet).

The program repeatedly opens the output file for appending a new line to it. That means that the OS must somehow find the end of the file and whereas that perhaps does not necessarily mean the OS has to "slurp" the whole file, it will have to walk the chain of disk-space to find where is the end of the file, then read the last few sectors in its buffer, append the new line and write out the buffer to disk again (either immediately or upon closing the file). And all this is done for each line added since the program opens and closes the output file for each new line.

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
  • Comment on Re^4: How does the while works in case of Filehandle when reading a gigantic file in Perl

Replies are listed 'Best First'.
Re^5: How does the while works in case of Filehandle when reading a gigantic file in Perl
by locked_user sundialsvc4 (Abbot) on Jan 30, 2015 at 22:14 UTC

    Indeed you are correct, Count ... I completely failed to notice that.   A boner like that can definitely torch any program’s performance.

    Upvotes coming your way (twice) for a “good catch.”