Re: Limiting Toke::Parser



Rob Dixon wrote:
Clinton JAmes wrote:
How do I stop the parser when I reach "pears".

You are presumably using HTML::TokeParser, and not Toke::Parse, Toke::Parse or
toke paser.

This should do what you want.

while (my $tag = $stream->get_tag('div')) {
next unless my $id = $tag->[1]{id};
last if $id eq 'mainbody';
}

while (my $tag = $stream->get_tag('a')) {
next unless $stream->get_trimmed_text eq 'pears';
print $tag->[1]{href}, "\n";
last;
}

I wouldn't interpret "when I reach 'pears'" that literally. Alternative solution:

while ( my $tag = $stream->get_tag ) {
if ( $tag->[0] eq 'a' ) {
print Dumper $tag;
}
last if $tag->[0] eq '/ul';
}

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
.