Perl 的 unlink 函式



描述

此函式將刪除 LIST 指定的檔案,如果未指定 LIST,則會刪除 $_ 指定的檔案。使用此函式時要小心,因為一旦檔案被刪除便無法恢復。

語法

以下是此函式的簡單語法 −

unlink LIST

unlink

返回值

此函式將返回已刪除檔案數。

示例

以下示例程式碼展示了此函式的基本用法,在 /tmp 目錄中建立兩個檔案 t1.txt 和 t2.txt,然後使用以下程式刪除這兩個檔案 −

#!/usr/bin/perl -w

unlink( "/tmp/t1.txt", "/tmp/t2.txt" );

當執行以上程式碼時,將生成以下結果 −

Both the files t1.txt and t2.txt will be deleted from /tmp.
perl_function_references.htm
廣告
© . All rights reserved.