Could you please remove the duplicate texts in readmore tags?
First of all there are many perl modules that do the XML parsing for you. Ok, you already are nearly finished, but next time you have to parse XML, you could use something like XML::Parser XML::Rules XML::Bare XML::Smart XML::Easy ...
To make regexes easier to read (and consequently debug) you could add an 'x' modifier and add spaces and line breaks to your regexes (remember to escape your spaces then). Also if you have to match literal '/' characters, using a different delimiter for the regex is recommended. Example:
$bBlkTx =~ s/<BlockAmendment [^>]+><P2>(.*?)<\/P2><\/Block Amendment>/ +\n<lq><P2>$1<\/P2>\n<\/lq>/gi; # versus $bBlkTx =~ s{ <BlockAmendment\ [^>]+ ><P2> (.*?) </P2></Block\ Ame +ndment> } { \n<lq><P2> $1 <\/P2>\n<\/lq> }xgi;
Notice that I highlighted the parts where the substitution happens through spaces. You could even extract part of the regexes into variables with meaningful names and make it even more obvious what you are parsing (though the positive effect in this example is rather small or even nonexistant):
$P2=qr'\s*<P2>\s*'xgi; $AmendmentPrefix= qr'BlockAmendment\ [^>]+ >'xgi; $AmendmentSuffix= qr'</P2></Block\ Amendment>'xgi; $bBlkTx =~ s{ $AmendmentPrefix $P2 (.*?) $AmendmentSuffix } { \n<lq><P2> $1 <\/P2>\n<\/lq> }xgi;
I know, this doesn't help you directly, but it helps you detect errors yourself and if you post more readable code, more people will make the effort to read your code
Do you know which regex is not working? If you don't know, just put print statements in your code that show you the data as it changes, or print the return values from the regexes, they tell you how many substitutions they made
If you know, make sure you add \s* patterns where line breaks or spaces occur
In reply to Re: Help required inText manipulation
by jethro
in thread Help required inText manipulation
by thirilog
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |