Re: Deleting files
- From: Tim S <ts@xxxxxxxxxx>
- Date: Sun, 03 Jun 2007 09:09:43 +0100
Bart Lateur wrote:
Anders F wrote:
Is there a Perl subroutine for deleting files?
There's a builtin. It's called "unlink".
http://perldoc.perl.org/functions/unlink.html
The reason for the odd name is because on Unix, there's no garantee that
if you succesfully apply this function on a file, that it will indeed be
deleted. There' something called a "hard link", so there can be multiple
directory entries, possibly in more than one directory, for the same
file. "unlink" will remove one such directory entry (called a "link").
Only when all links are gone, will the file contents indeed be deleted.
And indeed, when the final handle to the file is closed:
eg:
open F, ">Somefile";
unlink "Somefile";
print F "Wibble\n"; # File data exists, but there is no way to re-open
# it as the directory entry has gone. However, F may be cloned or passed to
# a sub process via fork().
close F; # Now the file goes away
Cheers
Tim
.
- References:
- Deleting files
- From: Anders F
- Re: Deleting files
- From: Bart Lateur
- Deleting files
- Prev by Date: FAQ 8.27 What's wrong with using backticks in a void context?
- Next by Date: Re: perl hash - data processing
- Previous by thread: Re: Deleting files
- Next by thread: Re: Deleting files
- Index(es):
Relevant Pages
|