in reply to Substitution inside tags, as 1 line

Try using the flip-flop operator:
perl -pe 'm|<pre>|...m|</pre>| and $_.="<p/>"' < your-html-file
Output :
<html> ...etc... <pre> <p/>Line 1 <p/>Line 2 <p/>...etc... <p/>Line n <p/></pre> <p/>...etc... </html>

     Have you been high today? I see the nuns are gay! My brother yelled to me...I love you inside Ed - Benny Lava, by Buffalax

Replies are listed 'Best First'.
Re^2: Substitution inside tags, as 1 line
by moritz (Cardinal) on Oct 14, 2008 at 06:35 UTC
    Nice, but why do you use <p/>? That's equivalent to <p></p>, thus inserting an empty paragraph before each line, which sounds rather nonsensical to me.

    If you try to be correct about p nesting, then write $_ = "<p>$_</p>" instead.

    Or use <br /> instead.

Re^2: Substitution inside tags, as 1 line
by tel2 (Pilgrim) on Oct 14, 2008 at 08:57 UTC
    That's a nice looking alternative, NetWallah. Not what I had in mind, but it has a certain elegence & simplicity.

    Would you then suggest I put the output of that through a subsitution that removes the two "</?pre>\n</p>" matches, to finish off my requirements? How would you do it?

    Thanks.

      Slightly uglier, getting rid of the extra </p> around the <PRE>, but still readable:
      perl -pe 'm|<pre>|..m|</pre>| and {m|</?pre>| or $_=qq|<p>$_</p>|} ' < + Your-file
      Also removed the unnecessary empty para (per mortiz, and kept it XHTML-compatible !

           Have you been high today? I see the nuns are gay! My brother yelled to me...I love you inside Ed - Benny Lava, by Buffalax

        Thanks again NetWallah.

        Here are some more alternatives, based on yours, which generate the output I was after, including removal of the <pre> tags. I guess your code is more correct via web standards, though.

        perl -ne 'm|<pre>|..m|</pre>| and s/\n/<p>\n/;m|</?pre>| or print' htm +lfile perl -ne 'chomp;m|<pre>|..m|</pre>| and $_.="<p>";s|</?pre><p>|| or pr +int "$_\n"' htmlfile

        Thanks for your ideas.