Re: LWP::HTML
Doug MacEachern (dougm@osf.org)
Thu, 21 Dec 1995 19:09:05 -0500
>Hm. This doesn't seem to be working for me:
>
> sub ptitle {
> my($node, $startflag, $depth) = @_;
> if ($node->tag eq 'title' && $startflag) {
> print $node->tag, "\n";
> }
> }
>
> $h = HTML::Parse::parse_htmlfile($ARGV[0]);
>
> $h->traverse(\&ptitle, 1);
>
>It doesn't print anything at all -- the file definitely has the <TITLE> tag.
>However -- if I change the test to look for the 'html' tag, it works.
Your callback function needs to return a true value until you find what you
are looking for,
sub ptitle {
my($node, $startflag, $depth) = @_;
if ($node->tag eq 'title' && $startflag) {
print $node->tag, "\n";
return 0; #got it, we're outta here
}
return 1; #keep looking
}
You were able to find 'html' since it is an element of the first node in the
tree.
perldoc HTML::Element says:
"If the return value from the callback is false then we will not traverse
the children."
-Doug
>s
>
>
>
>
>--
>+ + + + + | snewton@oac.hsc.uth.tmc.edu
> | Nobody else speaks for me,
> They've given you a number | and I speak for no one else.
> and taken away your name. | http://oac11.hsc.uth.tmc.edu/index.html
> | + + + + + +
>
>
>
>