in reply to Perl command line search and replace

You will also want to check those regular expressions. As they are they won't even compile. URLs contain lots of /s so you will probably want to choose a different delimiter, for example | or {}. Don't forget that . and ? are regex meta characters.

Something along the lines of will be better

s{\Qhttp://www.mydomain.com/script.pl?key=3\E} {http://www.mydomain.com/script.pl?key=4} s{\Q<font color="blue">\E} {<font color="red">}
By using the \Q \E pair you remove the need for most of the \ escapes and let perl handle the special characters. Aligning the replacement text with the original text also makes it easier to see what you are changing (I'm assuming that you have been convinced to put this in a file).

Replies are listed 'Best First'.
Re^2: Perl command line search and replace
by Anonymous Monk on Jun 28, 2011 at 16:38 UTC
    So if we are writing a simple script (I am assuming the script's name is test.pl):

    s{\Qhttp://www.mydomain.com/script.pl?key=3\E} {http://www.mydomain.com/script.pl?key=4}

    filename we are changing is called web.sh

    Would I write it from the command line like the following:

    perl test.pl web.sh