From: Jeremy Wells Date: 2006-11-24T11:39:07+09:00 Subject: Re: double-slashes in input causing trouble Jan Svitok wrote: > or you can use references: > > old_section = $1 > new_body = body.sub(old_section, bit_at_top + '\&') > > \& = the last match. > > if there was gsub instead of sub, this would be slower as the > replacement takes place on every occurence. In this case, however, > there's max 1 occurence. > > You can do as well: > - body = "" > - File.open(input, 'r') do |file| > - body = file.read > - end > + body = File.read(input) > > and > > File.open(input,'w') do |file| > file.write new_body > - end > + end unless new_body == body > thanks, thats useful to know for the future. this was something of a run once and its done program, and i've um run it now, so its done.