Home 


 
 

Perl File Copy

In this tutorial, we are going to learn on how to copy a file using Perl. You can script this process, which can be really handy while doing automation, backups, deployments, staging etc.

Perl has a module which we can use to copy file

To use this function in Perl we need to use the following syntax:

use File::copy

Lets create a file name example.txt and enter some text.

Now use copy function to copy the file.

copy ("filename" "copiedfilename")

Make sure you use the space between copy filename newfilename

The script below shows how to copy a file.

Perlcopyfile.pl

#!/usr/bin/perl

# Perl copy module
use File::Copy;

# Perl syntax to copy a file, where example.txt is orignal file name
copy ("example.txt", "copiedexample.txt");

exit; #Script will exit now
                

Output

copiedexample.txt

example.txt is copied to copiedexample.txt




© 2010 ToGoTutor | Copyright | Privacy Policy | |Subscribe to togotutor.com newsfeed|