Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HOW TO - Saving files without closing filehandles 1

Status
Not open for further replies.

kudithipudi

IS-IT--Management
Feb 11, 2002
29
0
0
A2
Hello Guys,
During the process of running my scripts/programs I usually open a bunch of file handles to write or read data to. I usually open the filehandle for log files at the starting of the program and close them at the end. Sometimes the script may error out or die unexpectadly. As a result all the logs I have written prior to the crash are lost. Is there any way to commit the data sent to the file handle to be explicitly written to disk rather than wait till the close(FILEHANDLE) is issued?

Thanks for the help..

- V.
 
Unbuffer the output of the filehandle that you are writting to. This will allow the script to write to the file in 'real-time'. An idiosyncratic way to do this is (do this just after you open() the filehandle):
Code:
select( (select(FILEHANDLE), $|++)[0] );
A more standard way is
Code:
my $oldfh = select(FILEHANDLE);
$| = 1;
select($oldfh);
jaa
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top