in reply to Re: Help required inText manipulation
in thread Help required inText manipulation

Thanks jethro,

Will update them.

The troubling regex is $xmlBody =~ s/$CbBlkTx/$bBlkTx/xgi; within the while.

just trying to replace back the replaced result '$bBlkTx' in "$xmlBody" but its not perfoming.

I may be wrong in trying this please add some advice in this.

#Processing BlockAmendments while ($xmlBody =~ m/(<BlockAmendment [^>]*>(.+?)<\/BlockAmendment +>)/gi){ $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>/xgi; $bBlkTx =~ s/<P2><Pnumber>([^<]+)<\/Pnumber><P2para><Text> +(.+?)<\/Text>(.*?)<\/P2para><\/P2>/\n<s1><no>($1)<\/no>\n<pt>$2<\/pt> +$3\n<\/s1>/xgi; $bBlkTx =~ s/<P3><Pnumber>([^<]+)<\/Pnumber><P3para><Text> +(.+?)<\/Text>(.*?)<\/P3para><\/P3>/\n<s2><no>($1)<\/no>\n<pt>$2<\/pt> +$3\n<\/s2>/xgi; $bBlkTx =~ s/<P4><Pnumber>([^<]+)<\/Pnumber><P4para><Text> +(.+?)<\/Text>(.*?)<\/P4para><\/P4>/\n<s3><no>($1)<\/no>\n<pt>$2<\/pt> +$3\n<\/s3>/xgi; $bBlkTx =~ s/<P5><Pnumber>([^<]+)<\/Pnumber><P5para><Text> +(.+?)<\/Text>(.*?)<\/P5para><\/P5>/\n<s4><no>($1)<\/no>\n<pt>$2<\/pt> +$3\n<\/s4>/xgi; } $bBlkTx =~ s/<\/pt>\n<\/s([0-9])><Text>(.+?)<\/Text>/ $2<\/pt> +<\/s$1>/xgi; print "$CbBlkTx\n\n=====>\n$bBlkTx\n\n"; $xmlBody =~ s/$CbBlkTx/$bBlkTx/gi; }

thanks

Replies are listed 'Best First'.
Re^3: Help required inText manipulation
by jethro (Monsignor) on Apr 12, 2011 at 13:17 UTC

    Ok, usual problem is that some characters in $CbBlkTx are regex special chars. If you use

    $xmlBody =~ s/\Q$CbBlkTx\E/$bBlkTx/xgi;

    instead, all special characters between \Q and \E are escaped. If you want more information try 'perldoc -f quotemeta', quotemeta is the function behind \Q\E

    UPDATE: Added missing word "information". I didn't want to insinuate that quotemeta delivers more escapes than \Q\E ;-)