Replacing a string in a fileby Avi (Acolyte)
|on Jul 16, 2003 at 16:32 UTC||Need Help??|
Avi has asked for the
wisdom of the Perl Monks concerning the following question:
I wanted to see what you guys can come up with for a way to simple change a string in a file.
I know, a very basic question, but I'm look for a better and more secure (in terms of writing -- would definitely not want this file to become corrupt or overwritten by simultaneous uses) way than what I have now.
Right now, I open up, read it's contents, close it, open up a temp file, write the new contents with the string replaced, close it, delete the original file and move the temp file to the original. Horrible, huh? There's got to be a better way than this. I just can't think of it! :( If there's a module out there to do this as well, let me know.
Thanks in advance.