My thought is this: that's just the way the filesystem works. You really only have two options: you can create a temporary file or you can store the contents of the file in memory. Then when you have finished changing the file you can write the new file to the old file's place. It sounds at first like a cumbersome way of going about it, but how else could you do it? You would have to make the whole system of file access and writing much more complicated if you allowed people to replace data from the file with data that was larger or smaller than the data being replaced. Do you see what I mean? If the thing you are replacing it with will always be the same length and the thing you are replacing, then you can use sysread or something along those lines, but then you're really doing a whole lot of extra work for no significant gain.
-----Original Message----- From: Tim Booher [mailto:[EMAIL PROTECTED]] Sent: Monday, September 02, 2002 12:09 PM To: [EMAIL PROTECTED] Subject: Read, Write and Append -- is there more? Hello, I am currently frustrated trying to do a simple find and replace on a file, but the three open options: Read, Write and Append don't seem to give me what I want. For example, Read, works on the finding, but nothing will replace. Write erases all the files and leaves me with blank files and append adds to the end. I tried something like: open(MYFILE,'+<',$myfile); and that didn't work. If you are interested here is my code: ... . . open(HTMFILE,'+<', $filename) or die "Can't Open: $!"; # now go through all .htm files and make changes while (<HTMFILE>) { $_ =~ s/leftmargin="0".*bgcolor="#3c3939"//g; $_ =~ s/bgcolor="\#5A5D4E"/class="topOfPic"/ig; } close(HTMFILE); . . . any thoughts . . ? thanks, tim -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
