Perl Topics





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
Perl Tutorial
Introduction Introduction
Installing Perl Installing Perl
Basics of Perl Basics of Perl
Scalar Variables Scalar Variables
Operators Operators
Control Structures Control Structures
Lists Lists
Array Array
Arrays Manipulation Arrays Manipulation
Arrays Functons Array Functions
Hash Hash
Hash Functions Hash Functions
String Functions String Functions
Regular Expression Regular Expression
Regular Expression Functions Regular Expression Functions
Numerical Functions Numerical Functions
List Functions List Functions
User Defined Function User Defined Function
File Handling File Handling
Forums Ask Your Doubts
Feedback Feedback
 





Perl File Handler - Copy File Function


Tutorials Perl

Topic

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:\programfiles\perl\bin\perl
    print "content-type: text/html\n\n";
    $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)





A Note
Simple introduction, basic CGI perl programming codes with examples. Do send your feedback or suggestions on this tutorial. This is a copyright content.

Other Links

web hosting