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!
With DEBUG on, this prints:#!/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"; } }
<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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |