in reply to Tip on better performance: Open and close output file or leave it open?

There are a handful of reasons to close and reopen a filehandle repeatedly:

If none of these apply, you can save some cycles by leaving it open. You may save a small bit of memory while it's not open. Whether either of these is worthwhile to worry about I can't say without measuring. I doubt this is a matter of any concern unless you're closing and reopening in a tight loop.

  • Comment on Re: Tip on better performance: Open and close output file or leave it open?