#! /usr/bin/perl use strict; use warnings; use Data::Dumper; use HTML::Parser; my $pa = qq~
This is a bad try to display text then code
#! usr/bin/perl use strict; use warnings; print "Hello World!";and then plain text again~; 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"); }