1. Perl
  2. builtin functions
  3. here

unlink function - delete file

You can use the unlink function to delete a file. The return value is the number of deleted files.

unlink $file;

Unlink function programming example

This is a programming example that deletes a file with the unlink function.

use strict;
use warnings;
use Fcntl;

# Delete the file.

# Create a file for preparation.
my $file = "example_20080520_$$. txt";

sysopen(my $fh, $file, O_CREAT | O_WRONLY | O_EXCL)
  or die "Unable to create $file .:$!";
close($fh);
print "Preparation:'$file' has been created.\n\n";

print "1: Delete the file.\n";
if (unlink $file) {
  print "'$file' has been deleted.\n";
}
else {
  print "'$file' could not be deleted.\n";
}

(Reference) sysopen function, Fcntl

Related Informatrion