6.4 刪除檔案

unlink 這個函式可以讓您刪除檔案,唯使用時請三思而後行,以免不小心刪掉重要的資料。用法如下:

unlink 檔案串列 (至少一個或一個以上)

用例:

#! /usr/bin/perl

$filename="/tmp/test.txt";

system("touch $filename");

sleep 20;

unlink $filename if -e $filename;

if (! -e $filename) { print "$filename 已被刪除\n"; }