homepage Welcome to WebmasterWorld Guest from 54.226.191.80
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

    
script will duplicate-rename data file
script will duplicate-rename data file
StopSpam




msg:432724
 4:06 pm on Jul 21, 2003 (gmt 0)

Hi all ...

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

 

sugarkane




msg:432725
 7:46 pm on Jul 21, 2003 (gmt 0)

There's a few options. The basic solution is to read the file into memory and then output the data to a new file (effectively copying it).

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)

StopSpam




msg:432726
 8:50 pm on Jul 21, 2003 (gmt 0)

it only has to work on unix/linux freebsd and so on ...

no nt windows severs

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved