Could someone please spare sometime lookinto the below issue?

Script:

#!/usr/local/bin/perl use strict; use warnings; undef $/; chomp($input=$ARGV[0]); open (A, "< $input") || die "Couldn't open the input"; open(B, ">A.xml") or die("Sorry!"); while (<A>){ $_=~s/\s\s//gi; $_=~s/\t//gi; $_=~s/^\n$//gi; $_=~s/\n//gi; $_=~s/’/&apos;/gi; $_=~s/—/&mdash;/gi; $_=~s/“/&ldquo;/gi; $_=~s/â€/&rdquo;/gi; print B $_; } close (A); close (B); open(C, "< A.xml") || die "$!"; open (Z, "> $input.sgm") || die "Can't write the output"; $file = <C>; #Body matter begins if ($file =~ m/(<Body [^>]*>(.*?)<\/Body>)/){ $xmlBody = $1; #. #. #. #Processing BlockAmendments while ($xmlBody =~ m/(<BlockAmendment [^>]*>(.+?)<\/BlockAmendment +>)/sgi){ $CbBlkTx = $1; $bBlkTx = $CbBlkTx; if ($bBlkTx =~ m/(<BlockAmendment [^>]+><P2>(.*?)<\/P2><\/Bloc +kAmendment>)/){ $bBlkTx =~ s/<BlockAmendment [^>]+><P2>(.*?)<\/P2><\/Block +Amendment>/\n<lq><P2>$1<\/P2>\n<\/lq>/gi; $bBlkTx =~ s/<P2><Pnumber>([^<]+)<\/Pnumber><P2para><Text> +(.+?)<\/Text>(.*?)<\/P2para><\/P2>/\n<s1><no>($1)<\/no>\n<pt>$2<\/pt> +$3\n<\/s1>/mgi; $bBlkTx =~ s/<P3><Pnumber>([^<]+)<\/Pnumber><P3para><Text> +(.+?)<\/Text>(.*?)<\/P3para><\/P3>/\n<s2><no>($1)<\/no>\n<pt>$2<\/pt> +$3\n<\/s2>/mgi; $bBlkTx =~ s/<P4><Pnumber>([^<]+)<\/Pnumber><P4para><Text> +(.+?)<\/Text>(.*?)<\/P4para><\/P4>/\n<s3><no>($1)<\/no>\n<pt>$2<\/pt> +$3\n<\/s3>/mgi; $bBlkTx =~ s/<P5><Pnumber>([^<]+)<\/Pnumber><P5para><Text> +(.+?)<\/Text>(.*?)<\/P5para><\/P5>/\n<s4><no>($1)<\/no>\n<pt>$2<\/pt> +$3\n<\/s4>/mgi; } $bBlkTx =~ s/<\/pt>\n<\/s([0-9])><Text>(.+?)<\/Text>/ $2<\/pt> +<\/s$1>/mgi; print "$CbBlkTx\n\n============\n"; print "$bBlkTx\n\n"; $xmlBody =~ s/$CbBlkTx/$bBlkTx/gi; } } print Z $xmlBody;

I'm sending you only the problamatical section from the script.

Requirement:

  1. Need to perform only in <Body ..</body> section from input XML. — clamped in $xmlBody variable
  2. Read the <BlockAmendment ...</BlockAmendment> chunks alone from the complete body content variable '$file' and do the simple find and replace. (refer #Processing BlockAmendments from the script)
  3. Then need to replace back the <BlockAmendment ...</BlockAmendment> with processed output from #2 point.
  4. Issue:

    #3 point has not performing within while loop!

    could you please helpout in this?

    Below are the two piece of particular input and required output

    piece of input:

    <BlockAmendment Context="unknown" TargetClass="unknown" TargetSubClass +="unknown" Format="double"> <P2> <Pnumber>3</Pnumber> <P2para><Text>At the time when the order is drawn up, the court office +r will—</Text> <P3> <Pnumber>a</Pnumber> <P3para><Text>where the order made is (or includes) a non-molestation +order; or</Text> </P3para> </P3> <P3> <Pnumber>b</Pnumber> <P3para><Text>where the order made is an occupation order and the cour +t so directs,</Text> </P3para> </P3> <Text>issue a copy of the order, indorsed with or incorporating a noti +ce as to the consequences of disobedience, for service in accordance +with paragraph (2).</Text> </P2para> </P2> </BlockAmendment>

    piece of output:

    <lq> <s1><no>&ldquo;(3)</no> <pt>At the time when the order is drawn up, the court officer will&mda +sh;</pt> <s2><no>(a)</no> <pt>where the order made is (or includes) a non-molestation order; or< +/pt> </s2> <s2><no>(b)</no> <pt>where the order made is an occupation order and the court so direc +ts, issue a copy of the order, indorsed with or incorporating a notic +e as to the consequences of disobedience, for service in accordance w +ith <cit><loc>paragraph (2)</loc></cit>.&rdquo;.</pt> </s2></s1> </lq>

    Thanks in Advance,

    Thirilog


    In reply to 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":



  5. Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  6. Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  7. Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  8. Please read these before you post! —
  9. 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
  10. 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;
  11. Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  12. See Writeup Formatting Tips and other pages linked from there for more info.