greatshots has asked for the wisdom of the Perl Monks concerning the following question:

monks

from a file I am looking for a pattern

<!DOCTYPE report SYSTEM "http://belief:8081/metrica_reporting/report_0 +1.dtd">
and I want to replace the above line as
<!DOCTYPE report SYSTEM "../../../../../Reporting/bin/report.dtd">
For doing the above task I used the below code
perl -nle 's/(.*) SYSTEM (.*)/$1 SYSTEM quotemeta("..\/../../../../Rep +orting/bin/report.dtd">)/g; print' 1-report.xml
won't I be able to use quotemeta inside the replace pattern ?

Replies are listed 'Best First'.
Re: using quotemeta in search and replace
by rhesa (Vicar) on Nov 16, 2006 at 02:37 UTC
    Why not use different delimiters on the whole replacement expression? I usually use curly braces when there are slashes in either side, e.g. s{some/path}{other/path}. See perlop under Quote-and-Quote-like-Operators for more details.

    Also note that perl comes with a -p switch, which does the -n and print for you.

    perl -ple 's{(.*) SYSTEM (.*)}{$1 SYSTEM "../../../../../Reporting/bin +/report.dtd">}g' 1-report.xml