You need unlink $FileName in the last line.
It will tell you how many files it deleted, and you could report this.
or, more conciselysub DeleteFile() { my $FileName = $_[0] . $t; $ret = unlink $FileName; die "No file called [$Filename] deleted\n" unless $ret == 1; }
sub DeleteFile() { my $FileName = $_[0] . $t; die "No file called [$Filename] deleted\n" unless unlink $FileName; }
Update: added third option.
or, you can be more friendly and return the value to the caller :
Which of the last 2 to choose depends on how important it is that the file is deleted or whether you have already checked its existence.sub DeleteFile() { my $FileName = $_[0] . $t; my $ret = unlink $FileName; warn "No file called [$Filename] deleted\n" unless $ret; return $ret; }
In reply to Re: How come I cannot delete file with unlink
by Brovnik
in thread How come I cannot delete file with unlink
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |