|
Prev: FAQ 9.21 How do I use MIME to make an attachment to a mail message?
Next: Perl LWP Issue with JSP's
From: Prasanth on 16 Apr 2008 09:06 When a file is open does unlink automatically deletes the file or it generates an error. Because I wrote a program to delete a file and regenerate the file. if the file is not deleted the data simply gets appended to the existing file. which results in wrong results
From: Joost Diepenmaat on 16 Apr 2008 09:21 Prasanth <prasanths89(a)gmail.com> writes: > When a file is open does unlink automatically deletes the file or it > generates an error. Because I wrote a program to delete a file and > regenerate the file. if the file is not deleted the data simply gets > appended to the existing file. which results in wrong results Unlink removes inodes, and it should succeed in that even if the file is opened by any process. It does not empty files, if that's what you mean. -- Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
From: A. Sinan Unur on 16 Apr 2008 09:25 Prasanth <prasanths89(a)gmail.com> wrote in news:270a0c78-9d5e-4486-8b35-b429c4d61755 @u36g2000prf.googlegroups.co m: > When a file is open does unlink automatically deletes the file or > it generates an error. Because I wrote a program to delete a file > and regenerate the file. if the file is not deleted the data > simply gets appended to the existing file. which results in wrong > results Hmmmm ... What is the question? If you script opened the file, close it before calling unlink. If the file is opened in exclusive mode by another process, I am not sure deleting it is the correct action in the first place. If you don't want your script to continue if unlink failed, you should check the return value of unlink. On the other hand, not that this will solve whatever problem you are having, I would not have messed with unlink at all: open my $out_h, '>', 'report.txt' or die "Cannot open 'report.txt': $!"; That truncates the file if it can be opened and would die if it cannot. Beats appending junk to a file. There are just two many combinations of problems and solutions that might apply to your post. Please elaborate after reading the posting guidelines for this group and may be taking a look at the following page: http://blogs.msdn.com/oldnewthing/archive/2008/04/15/8397753.aspx Sinan -- A. Sinan Unur <1usa(a)llenroc.ude.invalid> (remove .invalid and reverse each component for email address) comp.lang.perl.misc guidelines on the WWW: http://www.rehabitation.com/clpmisc/
From: A. Sinan Unur on 16 Apr 2008 09:29 Joost Diepenmaat <joost(a)zeekat.nl> wrote in news:87hce2gcko.fsf(a)zeekat.nl: > Prasanth <prasanths89(a)gmail.com> writes: > >> When a file is open does unlink automatically deletes the file or >> it generates an error. Because I wrote a program to delete a file >> and regenerate the file. if the file is not deleted the data >> simply gets appended to the existing file. which results in wrong >> results > > Unlink removes inodes, and it should succeed in that even if the > file is opened by any process. It does not empty files, if that's > what you mean. I am guessing the OP is on Windows where http://windowshelp.microsoft.com/Windows/en-US/help/47b3ce2b-3aec-401d-8be3-74434a1999831033.mspx Sinan -- A. Sinan Unur <1usa(a)llenroc.ude.invalid> (remove .invalid and reverse each component for email address) comp.lang.perl.misc guidelines on the WWW: http://www.rehabitation.com/clpmisc/
From: Ben Morrow on 16 Apr 2008 09:56 Quoth Joost Diepenmaat <joost(a)zeekat.nl>: > Prasanth <prasanths89(a)gmail.com> writes: > > > When a file is open does unlink automatically deletes the file or it > > generates an error. Because I wrote a program to delete a file and > > regenerate the file. if the file is not deleted the data simply gets > > appended to the existing file. which results in wrong results > > Unlink removes inodes, and it should succeed in that even if the file is > opened by any process. It does not empty files, if that's what you mean. Unlink removes *filenames*. Inodes are refcounted, and self-destruct when there are no refs to them (including open file descriptors). This only applies to Unixish filesystems, of course. Win32 won't let you unlink an open file (under normal circumstances). Ben
|
Next
|
Last
Pages: 1 2 Prev: FAQ 9.21 How do I use MIME to make an attachment to a mail message? Next: Perl LWP Issue with JSP's |