If you
link the original file to a backup filename then even while another process deletes the file you can still view the original content plus your additions by using the backup filename. One could even restore the original file, see example below:
use strict;
use warnings;
my $filename = 'logfile.txt';
my $backupfile = 'logfile.backup';
open(my $handle, '>>', $filename) or die;
link $filename, $backupfile;
unlink($filename);
print $handle "First line\n";
syswrite($handle, "Second line\n");
close($handle);
rename $backupfile,$filename; # ok to fail if $filename still exists
unlink $backupfile;
Note that while your filehandle remains open you can still write to the deleted file. Deleted files will not be visible in directory listings but the open handle would show up on the systems list of open handles (e.g. the command
lsof in Lunix and Unix systems would reveal them, provided you have enough system privileges).
And yes, while you keep writing to that file it will occupy more and more space on disk, a little nightmare for inexperienced system administrators that see disk usage grow and do not know why.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.