Welcome to WebmasterWorld Guest from 126.96.36.199
Forum member "netcommr" said in a earlyer question to me:
NEVER make direct edits to a data TXT file. Create a new file and populate it with the new data(what your keeping), then rename your old 'data.txt' file to 'data.txt.bu' for backup, then rename your new file to 'data.txt'. The reason for doing this is if the system faults in the middle of the operation you have not destroyed your data file.
I think he is 100% right .. beter duplicate a file before you go edit it
and have risk some one else write to it as well and then mess up all data
so my question is :::: .......
Can some one show me in perl code
How i can duplicate a existing file and rename it as well the file ecists n ned to create first ...
lets say i have file named news.txt
how do duplicate news.txt and name this second file bak.news.txt
i cant find this clear in my perl cook book
Then there's the File::Copy module which does the above for you wrapped in a simple function, or for a quick fix you can use shell commands enclosed in backticks - eg
$foo=`cp news.txt bak.news.txt`;
(That's on unix systems, I'm sure something similar can be done in Dos)