Yeah I'm leaving it alone for now. The socket server receives input episodically and could be invoked thousands of times per minute. But typically it 2 or 3 times per hour.
It just seems to be a design flaw to do the repeated open/closing stuff inside the while loop. But something that just came to mind is this: since the script never actually quits, would putting the open/close stuff outside the loop possibly lead to a memory leak? Since the close statement would never be executed if the script is functioning normally. Also, What benefit does flushing have? Would it help prevent memory leaks as per the above scenario or what? thanks again. On Mon, Mar 10, 2008 at 11:19 AM, Rob Dixon <[EMAIL PROTECTED]> wrote: > Jonathan Mast wrote: > > > > We have a socket server that, in addition to serving data, also writes > > logging statements to a file. > > > > My question concerns the correctness of how it accesses the log file. > The > > script is running continuously and all the log file IO stuff is inside > the > > main 'while' loop. > > The file is opened, written to and closed during each iteration of the > > loop. This seems very inefficient to me, all the opening and closings I > > presume are IO intensive. > > Would placing the opening and closing of the filehandle outside the > while > > loop be a good idea? > > Are you experiencing system problems that may be due to frequent file > openings and closures? If not then perhaps it's better to leave it > alone. > > If it would make you feel better then you could try the change you > suggest, but it is unlikely to have any real benefit unless the cycle > time of your loop is substantially under a second. In any case, you must > arrange to flush the output buffer either automatically, as John has > suggested, or explicitly. Take a look at IO::Handle. > > HTH, > > Rob > > >