gem555 has asked for the wisdom of the Perl Monks concerning the following question:

while(<DATA>){ s/<\w*>(.*)<\/w*>//g; } __DATA__ <p>Shouldn't I be allowed < to choose whom I want to associate with?< + Now, add the fact that my sister and her husband are still very < at +tached to my ex, as they should be. The problem is they now include " +her."</p> <span>Shouldn't I be allowed < to choose whom I want to associate with +?< Now, add the fact that my sister and her husband are still very < + attached to my ex, as they should be. The problem is they now includ +e "her."</span>
How to substitute all the '<' between the <\w*> and <\/w*> to

. I have to substitute all the characters '<' to '

' in between the <tags>.

Replies are listed 'Best First'.
Re: substitute character
by Utilitarian (Vicar) on Sep 02, 2009 at 08:19 UTC
    What is it with these text parsing questions all of a sudden?
    You want to remove any < between two words separated by spaces, at the moment you're not substituting with any thing. Read through prelre again.
    • capture the words and any spaces up to the > by using brackets
    • replace the entire string with the captured data
Re: substitute character
by arun_kom (Monk) on Sep 02, 2009 at 07:50 UTC
    Looks like your question is missing some text. You already had an advice in your previous post to preview your post before creating it.
      #!/usr/bin/perl my $line; while (my $line = <DATA>){ if($line =~ m/<span><p>(.*)/){ $line= $1; $line =~ s/</<\/p><p>/g; print $line; } } __DATA__ <span><p>This affected me deeply because < I was being treated for dep +ression then. < felt she was replacing me as mother and grandmother.
      suppose the input is like above specified. How to print the full line with substitution of <p> tags. Now the above code prints like
      This affected me deeply because </p><p> I was being treated for depres +sion then. </p><p> felt she was replacing me as mother and grandmothe +r.
      But I want the line similar to this
      <span><p>This affected me deeply because </p><p> I was being treated f +or depression then. </p><p> felt she was replacing me as mother and g +randmother.
        Consider this instead if your idea is to capture text between any kind of html start and end tag pair.

        if($line =~ m/<.+>(.+)<\/.+>/){ print $1; }

        UPDATE: I see now that the question i replied to has been replaced by you ... probably updated. So my answer above doesn't hold.