From: Li Chen Date: 2007-06-14T03:05:19+09:00 Subject: Re: why writing the file is partial > 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. What am I supposed to do if the replacement is not same size? Thanks, Li -- Posted via http://www.ruby-forum.com/.