in reply to Deleting on Text File

This works for the sample data you provided.
open (FILE, "sample.txt") || die "cannot open sample.txt"; while (<FILE>) { s/<\?--1-Stock3of1-->//; s/<b>This is option Stock 3 of 1<\/b>//; s/<\/\?--1-Stock3of1-->//; push (@words, $_); } close (FILE) || die "cannot close sample.txt"; open (FILE, ">sample.txt") || die "cannot open sample.txt"; foreach (@words) { print FILE; } close (FILE) || die "cannot close sample.txt";

Replies are listed 'Best First'.
Re: Re: Deleting on Text File
by Chady (Priest) on Oct 23, 2002 at 10:18 UTC
    this sample:
    <?--1-Stock3of1--> <b>This is option Stock 3 of 1</b> </?--1-Stock3of1--> <?--2-Second1of2--> <b>This is option Stock 3 of 1</b> </?--2-Second1of2--> <?--3-Third1of3--> <b>Option Third 1 of 3</b> </?--3-Third1of3-->
    would break under your code, you are assuming that you know the contents of the specific tags... when in fact you couldn't. so you need to strip off based on the tags..maybe HTML::TokeParser can work here..
    He who asks will be a fool for five minutes, but he who doesn't ask will remain a fool for life.

    Chady | http://chady.net/