How to copy a file and force overwirte in perl

J

Jay@HK

I have to write a perl script to copy and overwrite a file,
I tried to use file::copy but it seems no options for force overwrite
the destination file.
please advise.

Thanks!
 
P

Paul Lalli

Jay@HK said:
I have to write a perl script to copy and overwrite a file,
I tried to use file::copy but it seems no options for force overwrite
the destination file.
please advise.

What are you talking about? File::Copy *does* overwrite the
destination file.

$ cat > file1.txt
THIS IS FILE ONE
$ cat > file2.txt
this is the second file
$ perl -MFile::Copy -e'copy "file1.txt", "file2.txt"'
$ cat file2.txt
THIS IS FILE ONE
$

Paul Lalli
 
D

Dr.Ruud

Jay@HK schreef:
I have to write a perl script to copy and overwrite a file,
I tried to use file::copy but it seems no options for force overwrite
the destination file.
please advise.

s/file::copy/File::Copy/
 
S

Stan R.

Paul said:
What are you talking about? File::Copy *does* overwrite the
destination file.

$ cat > file1.txt
THIS IS FILE ONE
$ cat > file2.txt
this is the second file
$ perl -MFile::Copy -e'copy "file1.txt", "file2.txt"'
$ cat file2.txt
THIS IS FILE ONE
$

Paul Lalli

It's most like a permissions problem (which is why it's always good to
check return statuses & $!)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top