nglenn has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to use the following code to change some xml:
$xml = '<funcCall> <funcName>write</funcName> <rhsValue>crlf</rhsValue> <symConstant>loading</symConstant> <symConstant>| |</symConstant> <symConstant>lemmas</symConstant> <symConstant>| |</symConstant> <symConstant>for</symConstant> <symConstant>| |</symConstant> <variable><lx></variable> <symConstant>| |</symConstant> <symConstant>onto</symConstant> <symConstant>| |</symConstant> <variable><lms></variable> </funcCall>'; $xml =~ s& <funcCall>. <funcName>write</funcName>. <rhsValue>crlf</rhsValue> (.<(?:symConstant|variable)>[^<]*</(?:symConstant|variable)>)+ +. </funcCall> & my $text; foreach my $expr (1..$#-) { $text .= ${$expr}; } $text =~ s#<rhsValue>crlf</rhsValue>#\\n#; $text =~ s#</?symConstant>##sg; $text =~ s#</?variable>##sg; $text =~ s#.\| \|.# #sg; "<write string=\"$text\"/>"; &xse; print $xml;
I want "<write string="loading lemmas for <lx> onto <lms>"/>" but am getting "<write string=" <lms>"/>".
I don't understand why, but the @- only has one element. I know the match is fine because when I print $& I can see that the ()+ matched several items. Any suggestions?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: regex replace using position loop
by wind (Priest) on Mar 25, 2011 at 20:01 UTC | |
|
Re: regex replace using position loop
by Eliya (Vicar) on Mar 25, 2011 at 19:49 UTC | |
|
Re: regex replace using position loop
by choroba (Cardinal) on Mar 25, 2011 at 20:03 UTC |