in reply to Re: Unlinking a file when the file doesnt exist
in thread Unlinking a file when the file doesnt exist
Unfortunately, $! is garbage in that example. It would only be meaningful if stat (via -e) failed. One definitely cannot count on it having any info about an unlink error.
I recommend
for my $file (qw(files.txt data.txt)) { unlink($file) or $!{ENOENT} or die("Unable to unlink '$file': $!"); }
Or if one wants to clean up as many files as possible even if some can't be deleted,
my $success = 1; for my $file (qw(files.txt data.txt)) { if (!unlink($file) && !$!{ENOENT}) { warn("Unable to unlink '$file': $!"); $success = 0; } } die("Unable to cleanup") if !$success;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Unlinking a file when the file doesnt exist
by moritz (Cardinal) on Mar 22, 2011 at 21:19 UTC | |
by ikegami (Patriarch) on Mar 22, 2011 at 21:31 UTC | |
|
Re^3: Unlinking a file when the file doesnt exist
by Gulliver (Monk) on Mar 23, 2011 at 15:12 UTC | |
by ikegami (Patriarch) on Mar 23, 2011 at 15:47 UTC |