in reply to Speed of opening and closing a file 1000s times

Could you not open the infile, and all of the possible outfiles before you begin iterating through the infile? Then you just write to whichever file handle you decide upon. And at the end of the entire process (which with just a thousand lines or so should be pretty quick) close all filehandles at once.

Iterating through the same infile multiple times so as to be able to keep only one file opened at a time is a wasteful design, as is opening and immediately closing each outfile every time it is decided that something should be written to it. Open them all, do your work quickly, and then once you're done iterating, close them all.

I wonder if your reason for wanting to open and immediately close each file was to circumvent the need for proper file locking. If so, that too is a seriously flawed design in an environment where the files may be needed by multiple processes.


Dave


"If I had my life to live over again, I'd be a plumber." -- Albert Einstein
  • Comment on Re: Speed of opening and closing a file 1000s times