Perl link Function

Advertisements


Description

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.

Syntax

Following is the simple syntax for this function:

link OLDFILE,NEWFILE

Return Value

This function returns 0 on failure and 1 on success.

Example

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";
}

When above code is executed, it produced following result

Link created successfully


Advertisements
Advertisements