Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
The code above should substitute ^M with <br\/>> only with in the <Content> portion. and continuous <br\/>> should be replaced with single <br\/>> But the above code is replacing all the ^M after </Content> and before </ID>.#!/usr/bin/perl while (<DATA>) { if (/(<\w+>)/) { $flag = $1; } if($flag =~ m/<Content>/){ s/\^[A-Z]/<br\/>/g; } else{ s/\^[A-Z]//g; } print; } __DATA__ <ID>^M <Number>124^M</Number>^M <Content> Some of the week's top stories:^M EASTON AREA^M BETHLEHEM AREA^M CARBON, SCHUYLKILL AND REGION^M^M have charged his mother's boyfriend, Paul Hoffman, with third-degree m +urder. Officials said the charges were filed after an exhaustive inve +stigation that showed Miller, who died Sept. 25, had the mental capac +ity of a 12-year-old.^M </Content> ^M ^M ^M ^M ^M ^M </ID>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: substitution issue
by Marshall (Canon) on Nov 02, 2009 at 14:01 UTC | |
|
Re: substitution issue
by JavaFan (Canon) on Nov 02, 2009 at 11:58 UTC | |
by ikegami (Patriarch) on Nov 02, 2009 at 14:20 UTC | |
|
Re: substitution issue
by vitoco (Hermit) on Nov 02, 2009 at 12:50 UTC |