Bug in HTML::Element::traverse ?

Claus Schotten A (schotten@ert.rwth-aachen.de)
Tue, 31 Mar 98 14:53:27 +0200


Hi,

I don't know, if it's a bug or my fault, but this example shows some
nasty side effects:

require HTML::TreeBuilder;
my $lines = 0;
my $t = HTML::TreeBuilder->new;
$t->parse("<H1><A HREF=\"$0\">This Perl Script</A></H1>");
$t->traverse(
	     sub {
		 my($node, $start) = @_; 
		 if (ref $node && $start && $node->tag eq 'a') {
		     open(FILE,"<".$node->attr('href')) or die "open failed\n";
		     print "1: ",$t->as_HTML();
		     while (<FILE>) {$lines++;}
		     print "2: ",$t->as_HTML();
		 }
		 1;
	     });
print "$lines lines found\n";

----------

Therefore, I suggest to replace the variable of the for loop in
HTML::Element::traverse (currently $_) with a variable explicitely
declared using 'my'.

Ciao, Claus                         schotten@ert.rwth-aachen.de