in reply to Re: Re: Deleting on Text File
in thread Deleting on Text File
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.
Here are the results.$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-->
|
|
|
|---|