Perl File Handler - Copy File Function
How to copy a File in Perl programming?
Explanation
There are two functions in Perl to copy files they are "copy()", other is the "move()" function.
Copy:
This function is used to copy or to duplicate a file to in another file, if the same filename, at the same path, the old file will be rewritten.
Syntax:
copy (file1 ,file2)
In the above syntax the "file1" is the file to be copied into "file2", in case of files being two directories user can specify the path of both these files.
Example :
#! C:programfilesperlbinperl
print "content-type: text/htmlnn";
$file1 = "file1.txt";
$file2 = "cms/file2.txt";
copy($file1,$file2) or die "File cannot be copied.";
Result at file2.txt":
HScripts!
In the above example we copy the contents "file1.txt" to another file "file2.txt", using the copy function.
Move:
Move function in Perl copies a file from one location to another location, which are the arguments taken by the function.
Syntax:
move(location1,location2)