|The stupid question is the question not asked|
Using Perl Regex to find & replace large chunks in codeby jedikaiti (Friar)
|on Mar 11, 2013 at 18:03 UTC||Need Help??|
jedikaiti has asked for the
wisdom of the Perl Monks concerning the following question:
I have been asked to come up with a little something that could be used whenever we need to do a mass find-replace on large chunks of code. We're talking about CSTOL code that's edited in Emacs, and we need to swap out something like the below that shows up multiple times in anywhere from 1 - 10 (maybe more) different files.
I figured this would be do-able with regular expressions in Perl, but I have no idea how, as I've never tried to match more than a single line at a time.
So I consulted my good friend Google and found this: http://noctilucent.org/blog/2003/12/replacing-large-chunks-of-text-with-perl.html
So I gave that solution a shot. It seems to spit out a chunk of reasonable-looking regex into sub.pl, but beyond that does nothing, and I'm really not sure how the sub.pl output is supposed to work. For my example "code" above, I get this in sub.pl:
And, according to the web page, I can run that on my files (assuming similar file names) with this command: perl -p -0777 -i.bak sub.pl filename*.prc When I try that, nothing happens. My file doesn't get changed in any way (although the last modified date/time does get updated), but it does make a nice backup copy.
So, I'm lost. Can anyone help me find my way?
Swiss Army Nerd