J
Jeremy Wells
I'm writing a ruby program that reads a file, reads sections out of that
file, writes a header to each section and then writes the whole file
back to disk. The problem is that if the section contains "\\" which
mine does in places, ruby replaces these with a single "\" without my
asking it to.
Here is the basics of the program:
body = ""
File.open(input, 'r') do |file|
body = file.read
end
if body =~ /^section\sheader(.*)section\sfooter/mi
original_section = $1
new_section = bit_at_top + original_section
new_body = body.sub(original_section, new_section)
File.open(input,'w') do |file|
file.write new_body
end
end
If the original_section contains "\\" then this gets replaced by "\",
can I stop this happening?
Jeremy
file, writes a header to each section and then writes the whole file
back to disk. The problem is that if the section contains "\\" which
mine does in places, ruby replaces these with a single "\" without my
asking it to.
Here is the basics of the program:
body = ""
File.open(input, 'r') do |file|
body = file.read
end
if body =~ /^section\sheader(.*)section\sfooter/mi
original_section = $1
new_section = bit_at_top + original_section
new_body = body.sub(original_section, new_section)
File.open(input,'w') do |file|
file.write new_body
end
end
If the original_section contains "\\" then this gets replaced by "\",
can I stop this happening?
Jeremy