I'm implementing a simple logging module for a project but ran into a problem which is probably easy to fix.
I open a filehandle to the logfile which remains open until the long-running process ends. However, the logfile may be removed by another non-Perl process (so a file lock doesn't help here). After this happened, the printing to the filehandle still returns 1 but the file is not recreated again. Here's in short my problem:
my $filename = 'logfile.txt';
open(my $handle, '>>', $filename) or die;
print $handle "First line\n";
syswrite($handle, "Second line\n");
Is there a solution so I can detect that the file does not exists anymore? Both print and syswrite report no errors. Ofcourse I could use (-e $filename) but there's always this chance that the file is removed between the test and the print.
I can use other logging modules out there, but prefer to use my own light-weight module for simple logging.
Any help is as always appreciated! Cheers