in reply to Parsers overwriting each other

I guess the error comes from your class MUCParser, possibly in the subroutine num_of_tags, because HTML::Parser works for me independently. But HTML::Parser itself does not store any state, especially not anything like a tag count, so it is mostly interesting what your num_of_tags subroutine does and how/where it stores the tag count. If for example your MUCParser class looks like the following:

package MUCParser; use strict; use base 'HTML::Parser'; use vars '$tag_count'; sub new { my ($class,@args) = @_; ... my $self = $class->SUPER::new(@args); }; sub num_of_tags { return $tag_count; };

then, $tag_count is a global variable and all your MUCParser instances will share that variable. Some more information, like the (stripped down, relevant) source code of MUCParser is needed.

Replies are listed 'Best First'.
Re^2: Parsers overwriting each other
by bwgoudey (Sexton) on Jul 21, 2007 at 16:00 UTC
    Perhaps declaring my counter as a global is my problem. My code is quite similar to the example you gave, but mine is perhaps even more simple/naive. Here is my code
    use strict; use warnings; package MUCParser; use base "HTML::Parser"; my $num_of_tags; sub start { $tag_count+=1; } sub num_of_tags { return $tag_count; };
    I had assumed that declaring my tag_counter like that still meant that each instance had that. A quick google (now that I realise my problem) shows that the proper way to store my variables in the self hash reference. Sound like a better way of doing things? Time to test and see. Thanks heaps.