W
Willem
Hello,
For a program I'm writing that does a few regex-based substitutions
in a large file, I would like to see exactly what substitutions are
being done. I.E. Which strings were matched, and what they were
replaced by.
Or, in code: if I do:
$content =~ s/<add key="(.*?).foobar.\d+" value="Foo=.*?;(.*?"/>)/
<add key="$1.foobar.10" value="Foo=20;$2/g;
I want to display stuff like:
Substitution: '<add key="one.foobar.12" value="Foo=15;Bar=3"/>'
=> '<add key="one.foobar.10" value="Foo=20;Bar=3"/>'
Substitution: '<add key="two.foobar.12" value="Foo=15;Bar=8"/>'
=> '<add key="two.foobar.10" value="Foo=20;Bar=8"/>'
I have already succeeded in doing this by making a loop around
while ($content =~ /.../g)
where I used the @- and @+ arrays to get at the matches, and then
manually fill in the $1 .. $x variables.
That's pretty complicated, however, and also the actual substitution is
pretty hairy too (I had to do another s/// with the strings I just created
and displayed).
Is there an easier way to get at what a substitution is doing ?
SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
For a program I'm writing that does a few regex-based substitutions
in a large file, I would like to see exactly what substitutions are
being done. I.E. Which strings were matched, and what they were
replaced by.
Or, in code: if I do:
$content =~ s/<add key="(.*?).foobar.\d+" value="Foo=.*?;(.*?"/>)/
<add key="$1.foobar.10" value="Foo=20;$2/g;
I want to display stuff like:
Substitution: '<add key="one.foobar.12" value="Foo=15;Bar=3"/>'
=> '<add key="one.foobar.10" value="Foo=20;Bar=3"/>'
Substitution: '<add key="two.foobar.12" value="Foo=15;Bar=8"/>'
=> '<add key="two.foobar.10" value="Foo=20;Bar=8"/>'
I have already succeeded in doing this by making a loop around
while ($content =~ /.../g)
where I used the @- and @+ arrays to get at the matches, and then
manually fill in the $1 .. $x variables.
That's pretty complicated, however, and also the actual substitution is
pretty hairy too (I had to do another s/// with the strings I just created
and displayed).
Is there an easier way to get at what a substitution is doing ?
SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT