in reply to Deleting on Text File

Your match loop matches a particular pattern in the file ignoring all other sections. The matched section that you want to remove is identified by a condition (location and obj_name) The problem is that you always add the just matched section to $list. The line adding on to $list should be in your conditional statement.
unless (($a eq $location) and ($b eq $obj_name)) { $list=$list. "<?--$a-$b-->$c</?--$d-$e-->\n"; }
This should add to the list except when the condition is true. I would have like to test this code but you did not give any sample data.

P.S. I noted that your question has a low reputation. I suspect that the lack of sample data may have contributed to it.

Disclaimer

Replies are listed 'Best First'.
Re: Re: Deleting on Text File
by Anonymous Monk on Oct 22, 2002 at 19:28 UTC
    Thanks but, that deletes the entire file.
    Here is a sample test.txt data file
    <?--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-->

    Let's say I want to delete this part of the text data
    <?--1-Stock3of1--> <b>This is option Stock 3 of 1</b> </?--1-Stock3of1-->

    That's my question how I a get rid of that part and leave the rest of the data alone. Thank you!!!!
      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