P
Paul Fox
hi all,
i have a text file with various lines, and i want to alter some of these
using regex and gsub.
so i have patterns={/some_pattern/=>"replacement text"}
and i'm thinking this:
in = File.open(filename)
while (line=in.gets)
if line.strip =~ pattern
line.gsub(pattern,patterns[pattern])
end
end
but i'm not sure if that's efficient? and of course, i'm struggling on
the best way of writing those changes back into the file.
any thoughts?
thanks,
f.
i have a text file with various lines, and i want to alter some of these
using regex and gsub.
so i have patterns={/some_pattern/=>"replacement text"}
and i'm thinking this:
in = File.open(filename)
while (line=in.gets)
if line.strip =~ pattern
line.gsub(pattern,patterns[pattern])
end
end
but i'm not sure if that's efficient? and of course, i'm struggling on
the best way of writing those changes back into the file.
any thoughts?
thanks,
f.