I didn't know in the first thread what you wanted to do, "text is missing" was not very informative!

Parsing this HTML stuff can get complicated and I would agree with GrandFather that an HTML module is best for complex situations.

But....here is a one regex way of doing it (that seems to be what you want). This is only 5, "non-trivial" lines of code, but it did take me some time to write them. There is of course some stuff that is specific to your application and the example that I had!

#!/usr/bin/perl -w use strict; use constant DEBUG => 1; #makes lines easier to see on screen while (<DATA>) { if ( my ($title, $body) = ($_ =~ /<TITLE>.*?(<p>.+?)<BODY>.*?(<p>.*)/)[0,1] ) { $title .= "</p>"; $body .= "</p>"; $title =~ s|<[^a/p]|<p>|g; $title =~ s|.<p>|.</p><p>|g; $title =~ s|</p>|</p>\n|g if DEBUG; $body =~ s|<[^a/p]|<p>|g; $body =~ s|.<p>|.</p><p>|g; $body =~ s|</p>|</p>\n|g if DEBUG; print "<TITLE>\n$title\n\n", "<BODY>\n$body\n"; } }
With DEBUG on, this prints:
<TITLE> <p>Dogs may not smarter than 6-year-olds, but researchers suggest cani +nes might be on par with 2-year-olds.</p> <p>Psychologist Stanley Coren says, "We do know that dogs understand f +ar more than we credit them with, from about 165 words to 250 words." + Even better than understanding our words, dogs know our hand gesture +s and body postures. Dogs may, in fact, far exceed 2-year-olds when i +t comes to reading emotions.</p> <BODY> <p>Developmentally, 2-year-olds are generally more interested in thems +elves, while dogs do care how their people feel, and instantly recogn +ize a change in emotion.</p> <p>"While your dog can't comprehend that you just received a traffic v +iolation, he can tell that you're upset the second you walk through t +he door," Coren says. "In fact, dogs can detect some subtle changes w +hich even adults can't," adds Coren. "We can't smell cancer or predic +t seizures, as dogs can..</p> <p>When I posted this story on my Facebook Fan page recently (<a href= +"http://www.new.facebook.com/pages/ Steve-Dale/50057343596?ref=ts">ww +w.new.f acebook.com/pages/Steve-Dale/50057343596?ref=ts, or simply ty +pe Steve Dale into the Facebook search), I received some interesting +responses.</p> <p>Kelle: "Heck, my Italian Greyhound is smarter than most college stu +dents..</p> <p>Karen: "Depends on how you define smart.</p>

In reply to Re: p tag substitution by Marshall
in thread p tag substitution by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.