Stupid Perl question
Jul. 2nd, 2007 05:42 pmHey people--
Say you were writing a quick & dirty Perl script to hunt through your source code for a particular chunk of broken code, in order to replace it with a fixed version. Being code, the text you're hunting for is chock full of variable names & other weird punctuation marks. Now, the obvious thing to do would be to use the s/// operator ... except that s/// tries to compile your search string into a regexp, which breaks your quick & dirty Perl script. (And you don't really want to go through the code and backslash all the backslashable characters, because the chunk is nontrival, and right now it works.)
I mean, there's got to be a quick & dirty way of substituting text in Perl, right? There's got to be a way of turning off regular expressions?
Suppose further that you've just spent 45 minutes banging your head against this problem, and are starting to suspect that a brute force copy & paste on all 50 or so source files would have been finished & tested by now.
What do you do?
Say you were writing a quick & dirty Perl script to hunt through your source code for a particular chunk of broken code, in order to replace it with a fixed version. Being code, the text you're hunting for is chock full of variable names & other weird punctuation marks. Now, the obvious thing to do would be to use the s/// operator ... except that s/// tries to compile your search string into a regexp, which breaks your quick & dirty Perl script. (And you don't really want to go through the code and backslash all the backslashable characters, because the chunk is nontrival, and right now it works.)
I mean, there's got to be a quick & dirty way of substituting text in Perl, right? There's got to be a way of turning off regular expressions?
Suppose further that you've just spent 45 minutes banging your head against this problem, and are starting to suspect that a brute force copy & paste on all 50 or so source files would have been finished & tested by now.
What do you do?