sanjeeb wrote:
martin wrote:
Do I need to close an open file, before unlinking it or can I
simply unlink (delete( it without worring to close it.
case 1) file has been opened for reading
case 2) file has been opened for writing.
I think you can't delete a file while it's opened.
To be safe close the handle and unlink the file, because in perl
unlink will not give error
Yes it does "give error":
$ perl -e' unlink q[DoesNotExist] or die "unlink: $!" '
unlink: No such file or directory at -e line 1.
...
Prog 1:
###################
open(handle,">asdf");
close handle;
unlink asdf;
O/p
It will delete the file .
prog 2
###################
open(handle,">asdf");
unlink asdf;
It will not delete the file and doesnt give an error also.
By your reasoning, no call in Perl returns an error.
For example, if the open call failed above, you would not get a message
either (unless you have Fatal'ized it).
You have to check if the call succeded. If the call failed, $! will
contain the error. You can then choose to report it or not.
That is what John was demonstrating.
As a side note, unlinking an open file is possible (and advisable in
certain situations) on some operating systems other than Windows.
Sinan
--
A. Sinan Unur <
[email protected]>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html