in reply to Re: Re: with better example
in thread replacing text in specific tags

texuser, while your code is correct and it is great that you now found a solution on your own, I do have some thoughts to share with you on your code:
Last thing: I tested both your and my code on a file named "temp.in", and both worked. The input file consisted of your three input lines, the output file of your three output lines in both cases. Considering the sbove, if you would like to get the program running, as to parse your input file in one go, I'llbe happy to help you.
Oh, yes, and a ++ for you for putting together your own piece of code that works for you.
Cheers, CombatSquirrel.

Replies are listed 'Best First'.
Loop and Find & Replace
by texuser74 (Monk) on Aug 25, 2003 at 04:33 UTC
    Hi, Thanks for your comments. One more small doubt i have.

    here is the input data

    <input> This is to test. this is to test <p>This is to test. This is to test</p> <p>This is to test. This is to test</p> This is to test. this is to test </input> <output> This is to test. this is to test <p>This is to test. This is to test</p> <p>This is to test. This is to test</p> This is to test. this is to test </output>
    i.e. i want to make the <p>...</p> as single line. i mean delete the carrage returns only inside <p>...</p> my following code does the job, but only for the last <p>...</p>. i don't know how to loop it here. pls suggest
    $infile = $ARGV[0]; open(IN, '<', "temp.in") || die "\nCan't open temp.in \n"; open(OUT, '>' "temp.out"); $/=""; while(<IN>) { if($_=~s/(.*)&lt;p&gt;(.*)\<\/p\>(.*)//ms) { $pre = $1; $par = $2; $pos = $3; $par=~s#\n# #ig; print OUT "$pre&lt;p&gt;$par\<\/p\>$pos"; } } close(IN); close(OUT);
    Note: also please let me know how to include the source code in this page, any special tags for that? i mean the code formatting is often getting messed when i post

    edited by ybiC: Reformatted - balanced <code> tags around sample input and code

      Your formatting is pretty much screwed up. To be honest, I don't see what you are saying. Try to fix it and I'll do my best to help you. In the meantime I'd recommend the HTML::TokeParser Tutorial. In general, if you do extensive HTML or XML processing, consider using a module.
      Cheers, CombatSquirrel.
        Hi, Thanks for your comments. One more small doubt i have.

        here is the input data

        <input> This is to test. this is to test <p>This is to test. This is to test</p> <p>This is to test. This is to test</p> This is to test. this is to test </input>
        <output> This is to test. this is to test <p>This is to test. This is to test</p> <p>This is to test. This is to test</p> This is to test. this is to test </output>
        i.e. i want to make the <p>...</p> as single line. i mean delete the carrage returns only inside <p>...</p> my following code does the job, but only for the last <p>...</p>. i don't know how to loop it here. pls suggest
        $infile = $ARGV[0]; open(IN, '<', "temp.in") || die "\nCan't open temp.in \n"; open(OUT, '>' "temp.out"); $/=""; while(<IN>) { if($_=~s/(.*)&lt;p&gt;(.*)\<\/p\>(.*)//ms) { $pre = $1; $par = $2; $pos = $3; $par=~s#\n# #ig; print OUT "$pre&lt;p&gt;$par\<\/p\>$pos"; } } close(IN); close(OUT);
        Note: also please let me know how to include the source code in this page, any special tags for that? i mean the code formatting is often getting messed when i post

        edited by ybiC: Reformatted to avoid lateral scrolling in browser window - balanced <code>tags around example input+output and code