Here is a sample program using the code I suggested and
the data you supplied.
The criteria for deletion are the values of the first two extracted fields of your sample record. I hard coded the values for this demo.
Please note (as mentioned in another node) that if your data
contains any kind if html code this technique will fail
if the data matches your delimiters.
$location = "1"; # hard code deletion info
$obj_name = "Stock3of1";
undef $/; # Slurp mode
$_ = <DATA>;
print "-Before=====================================\n";
print "$_\n";
while(/<\?--([^-]*)-([^-]*)-->(.*?)<\/\?--([^-]*)-([^-]*)-->/sg){
$a=$1; $b=$2; $c=$3; $d=$4; $e=$5;
# debug output
# print "-A--------\n$a\n-B--------\n$b\n-C--------\n$c\n-D------
+--\n$d\n-E--------\n$e\n-eor------\n\n";
unless (($a eq $location) and ($b eq $obj_name)) {
$list=$list. "<?--$a-$b-->$c</?--$d-$e-->\n";
}
}
print "-After======================================\n";
print "$list\n";
__END__
<?--1-News1-->
<b>This is option News 1 of 1</b>
</?--1-News1-->
<?--1-Weather2of1-->
<b>This is option Weather 2 of 1</b>
</?--1-Weather2of1-->
<?--1-Stock3of1-->
<b>This is option Stock 3 of 1</b>
</?--1-Stock3of1-->
<?--2-Second1of2-->
<b>Option Second 1 of 2</b>
</?--2-Second1of2-->
<?--3-Third1of3-->
<b>Option Third 1 of 3</b>
</?--3-Third1of3-->
Here are the results.
-Before======================================
<?--1-News1-->
<b>This is option News 1 of 1</b>
</?--1-News1-->
<?--1-Weather2of1-->
<b>This is option Weather 2 of 1</b>
</?--1-Weather2of1-->
<?--1-Stock3of1-->
<b>This is option Stock 3 of 1</b>
</?--1-Stock3of1-->
<?--2-Second1of2-->
<b>Option Second 1 of 2</b>
</?--2-Second1of2-->
<?--3-Third1of3-->
<b>Option Third 1 of 3</b>
</?--3-Third1of3-->
|
-After======================================
<?--1-News1-->
<b>This is option News 1 of 1</b>
</?--1-News1-->
<?--1-Weather2of1-->
<b>This is option Weather 2 of 1</b>
</?--1-Weather2of1-->
<?--2-Second1of2-->
<b>Option Second 1 of 2</b>
</?--2-Second1of2-->
<?--3-Third1of3-->
<b>Option Third 1 of 3</b>
</?--3-Third1of3-->
|
Disclaimer
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.