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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.