Perl 連結函式



說明

此函式建立一個新檔名 NEWFILE,並將其連結到檔案 OLDFILE。此函式建立一個硬連結;如果你想要一個符號連結,請使用 symlink 函式。

語法

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

link OLDFILE,NEWFILE

返回值

此函式在失敗時返回 0,在成功時返回 1。

示例

以下是顯示其基本用法的示例程式碼,它將使用現有檔案建立新檔案 −

#!/usr/bin/perl

$existing_file = "/usr/home/test1";
$new_file = "/usr/home/test2";
$retval = link $existing_file, $new_file ;
if( $retval == 1 ) {
   print"Link created successfully\n";
} else {
   print"Error in creating link $!\n";
}

當執行以上程式碼時,它產生以下結果 −

Error in creating link No such file or directory
perl_function_references.htm
廣告
© . All rights reserved.