Here is an HTML::Parser API2 example that show you the basics. You basically need to deal with 2 cases - one where you have a </p> and one where you don't. You need to maintain state between the callbacks so you know what to do.

my $data=<<DATA; <p>foo <h4>h4.1</h4> <p>bar <p>baz <h4>h4.2</h4> <p>bar</p> <p>baz</p> <h4>h4.3</h4> <hr> <p>bar <p>baz DATA { package MyParser; use base 'HTML::Parser'; sub start { my($self, $tagname, $attr, $attrseq, $origtext) = @_; if ( $self->{blockquote} ) { # deal with no closing </p> print "</blockquote>\n$origtext"; $self->{blockquote} = 0; } elsif ( $tagname eq 'p' and $self->{h4last} ) { print '<blockquote>'; $self->{blockquote} = 1; } else { print $origtext; } $self->{h4last} = $tagname eq 'h4' ? 1 : 0; } sub end { my($self, $tagname, $origtext) = @_; if ( $self->{blockquote} and $tagname eq 'p' ) { print '</blockquote>'; $self->{blockquote} = 0; } else { print $origtext; } } sub text { my($self, $origtext, $is_cdata) = @_; print $origtext; } sub comment { my($self, $origtext ) = @_; print $origtext; } } my $p = MyParser->new; $p->parse($data);

cheers

tachyon


In reply to Re: HTML module help please? by tachyon
in thread HTML module help please? by Cody Pendant

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.