Perl link 函数

描述

This function creates a new file name, NEWFILE, linked to the file OLDFILE. The function creates a hard link; if you want a symbolic link, use the symlink function.


语法

以下是此函数的简单语法 −

link OLDFILE,NEWFILE

返回值

此函数在失败时返回 0,在成功时返回 1。


示例

Following is the example code showing its basic usage, this will create new file using existing file −

#!/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 函数参考