in reply to Not printing to file, but print to screen ok
A more normal order of things would be to open the output file much earlier. The reason for this is that we don't want to do a lot processing only to find out later that we can't write the result because we don't have the correct file permissions or path! I have seen programs bomb after 2-5 days of running because of this! So bad idea.
If your program doesn't run for a "long time", I see no reason the close the file handle, FH. When your Perl program exits, the OS will close that file handle. You can open a new file with the same File Handle and the OS will "recycle it". No problem. Anyway if your program just uses a couple of file handles and runs for some seconds or minutes, there is no need to "close" the file which releases some resources back to the OS.
There will be at MOST one line in your FH output file. Open this file handle earlier.
|
|---|