I am trying to create a perl script that will read arguments from a pipe dilimted file with each line of the file containing a search term and a replace term delimited by the pipe. I want it to work somewhat as sed will with the -f switch and a command file.
What I have works well if I put only literal strings in my searchterms file, but if I try it with perl regular expressions I am completely unsuccessful. I am not sure just how to process the terms so that perl will handle them as regexes. Here is what I am trying to do:
Here is a sample searchterms file
When run with terms as in the first line os the searchterms I get the subsitution expected. But when run with the regex my substitution is exactly like
.
I have been hunting the newsgroups and a fairly extensive perl library but am obviously missing the cogent point. Can anyone point me in the right direction?
Thanks
Derek
What I have works well if I put only literal strings in my searchterms file, but if I try it with perl regular expressions I am completely unsuccessful. I am not sure just how to process the terms so that perl will handle them as regexes. Here is what I am trying to do:
Code:
open TERMS, "$searchterms" or die "Can't open the replacement terms file because: $!\n";
while (<TERMS>) {
($srch,$repl) = split(/\|/);
chomp($srch);
chomp($repl);
$file =~ s!$srch!$repl!ig;
}
close TERMS;
Here is a sample searchterms file
Code:
[URL unfurl="true"]http://www.thisdomain.com|http://www.that.domain.com[/URL]
(<a href ? = ?"?[URL unfurl="true"]http://www\.)thisdomain(\.[/URL][a-d]{3,})|$1thatdomain$2
When run with terms as in the first line os the searchterms I get the subsitution expected. But when run with the regex my substitution is exactly like
Code:
$1thatdomain$2
I have been hunting the newsgroups and a fairly extensive perl library but am obviously missing the cogent point. Can anyone point me in the right direction?
Thanks
Derek