Oliver Block <[EMAIL PROTECTED]> writes:
> Am Dienstag, 25. April 2006 22:09 schrieben Sie:
> > This is not supposed to be for parse_file(). It would be helpful if
> > you try to produce a small test program that demonstrates this.
>
> Yes, of course. I hope I didn't forget any important line of code;
You forgot to call parse_file().
--Gisle
> ######## output ###########
> start_document 23:43:45.188784
> ########################
>
> with $p->eof();
> ######## output ###########
> start_document 23:51:25.93499
> end_document 23:51:25.96407
> ########################
> ####### calling script ########
> ..
> my $p = MyParser->new;
> $p->parse("localfile.html"); # local html file
> #$p->eof();
> ..
> ########################
> ####### MyParser.pm ########
> package MyParser;
>
> use strict;
> use HTML::Parser;
> use Time::HiRes qw( gettimeofday );
>
> my $class;
> my $p;
> ..
> sub new {
> $class = shift;
> my $self = { };
> bless $self, $class;
> $self->_init();
> return $self;
> }
> sub _init() {
> $p = HTML::Parser->new( api_version => 3,
> start_h => [ \&_start_handler, 'tagname, attr' ],
> end_h => [ \&_end_handler, 'tagname' ],
> text_h => [ \&_text_handler, 'self' ],
> start_document_h => [ \&_start_document_handler, 'self' ],
> end_document_h => [\&_end_document_handler, 'self' ]);
> }
> sub parse() {
> my ($class, $s, $uri) @_; # local $class
> ...
> $p->parse($s);
> }
> sub _start_document_handler {
> printTimestamp $class, "start_document";
> }
> sub _end_document_handler {
> printTimestamp $class, "end_document";
> }
> sub eof() {
> return $p->eof();
> }
> sub printTimestamp {
> my ($class, $caller, $comment) = @_;
> my($sec, $min, $hour) = localtime(time);
> my ($hsec, $msec) = gettimeofday; # $hsec not used
> printf("%s %s %2d:%2d:%2d.%d\n", $caller, $comment, $hour, $min, $sec,
> $msec):
> }
> 1;
> __END__