From: Li Chen Date: 2007-07-31T05:46:18+09:00 Subject: Re: why writing the file is partial Rick Denatale wrote: > He needs to seek back to the beginning of the line before he writes: > > file.each_line do |line| > if pat.match(line) > line.gsub!(pat,sub) #replace the line in place > file.seek(-line.length, IO::SEEK_CUR) > file.print line #write/update the file > end > end > end > > But this will only work in the case where the replacement is the same > length at the original, if you you're either going to leave stuff > behind, or will overwrite the next line. In either case you're more > likely to end up with gibberish than something you like. HI Rick, Now I work on a small project with deals with process files and upgrade the them in place. Just as you point out the #seek only works if the replacement is the same as the original. And the replacement will get unpredictalbe results or fail if the length is different. I wonder if other methods are available for this situation in Ruby? Thanks, Li -- Posted via http://www.ruby-forum.com/.