reneeb has asked for the wisdom of the Perl Monks concerning the following question:
<p>This is a bad try to display text then code <pre>#! usr/bin/perl use strict; use warnings; print "Hello World!";</pre> and then plain text again</p>
#! /usr/bin/perl use strict; use warnings; use Data::Dumper; use HTML::Parser; my $pa = qq~ <p>This is a bad try to display text then code <pre>#! usr/bin/perl use strict; use warnings; print "Hello World!";</pre> and then plain text again</p>~; my $p = HTML::Parser->new(); $p->handler(start => \&start_handler,"tagname,self"); $p->parse($pa); sub start_handler{ my ($tag,$self) = @_; my $text = ''; if($tag eq 'pre'){ print "Pre:\n"; } $self->handler(text => sub {$text .= shift},"dtext"); $self->handler(end => sub {my $tag = shift; print $text,"\n\n" if($ +tag eq 'pre' || $tag eq 'p');},"tagname"); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: split html via HTML::Parser
by saskaqueer (Friar) on Feb 28, 2005 at 12:11 UTC | |
by reneeb (Chaplain) on Feb 28, 2005 at 12:22 UTC |