9.2.3. Discussion
The unlink function takes its name from the Unix
syscall. Perl's unlink takes a list of filenames
and returns the number of filenames successfully deleted. This return
value can then be tested with || or
or:
unlink($file) or die "Can't unlink $file: $!";
unlink doesn't report which filenames it couldn't
delete, only how many it deleted. Here's one way to test for
successful deletion of many files and report the number deleted:
unless (($count = unlink(@filelist)) = = @filelist) {
warn "could only delete $count of "
. (@filelist) . " files";
}
A foreach over @filelist would
permit individual error messages.