From: Robert Klemme Date: 2009-09-02T20:55:53+09:00 Subject: Re: Best Practice for Multiline Regexps 2009/9/2 Shot (Piotr Szotkowski) : > Lance Pollard: > >> 1) Read file to String, match string against first pattern, read next >> file into String, match with same pattern... once I've gone through >> all the files with the first pattern, start over with the next >> pattern. > >> 2) Read file to String, match whole string against all >> 20 patterns, go to next file, match against 20 patterns... > > The only advantage of 1) over 2) is that if you have a situation where > a combination of pattern 18 with file X breaks (because the pattern > didn’t foresee some peculiar corner case which manifests only in file > X), then – assuming you take snapshots of the operation after every > pattern replace is over – the first approach will let you keep the work > done by the first 17 pattern replacements and re-run the process from > pattern 18 on, while the second approach will mean you have to roll back > everything and redo all of the work that succeeded one time already. Excellent point! With a complex operation like this I would keep backups of all original files anyway. Maybe even copy the whole directory tree before changing anything. That way you can check with diff what changed, roll back etc. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/