Overwrite read-only file with the Perl File::Copy function
I need to copy read-only files in Perl. I tried using Perl::Copy function, but it fails in case the file already exist开发者_如何学Pythons and isn't writable.
Is there a force argument I can give to the copy function?
I want to avoid changing permissions of files, or removing the destination file before copying.
Seems like you are giving yourself unreasonable requirements. I think the best solution is to remove the destination file before copying, which should be as simple as:
unlink $dest_file if -e $dest_file;
with out changing permission you can't overwrite the file.in perl no function for force fully you overwrite
To complete the Ron answer, the Perl documentation says :
copy will not overwrite read-only files.
That's why we need to change permissions or delete file before copy.
精彩评论