Losing a file handle in perl

Adil Kodian akodian-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org
Tue Dec 14 00:48:31 UTC 2004


   The script seems to be working fine because the program is working
through and past this call but what I do lose is an open filehandle I
use to write my logs out to. The first sub routine called by the program
will write out to the file right up to the last line but once it returns
the main program will no longer write out to the open file.




not specific to perl - for programs that dont have much of IO - an easy way
is to always do an 'append' open of a file every time you want to write to
it, and then flush the buffer and close it.

If FilePointer == NULL then FilePointer = fopen("filename","append");

This way you always get all the contents of the file even if the program
crashes in the middle.
The first time you open the file you open it as write - in case you want to
blank the file. Also if youre forking new processes in perl, always remember
to have a thread_id written in a filename.lock file - so that other
processes dont open the file before youve closed it in one process.





--
The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml





More information about the Legacy mailing list