Clinton JAmes wrote: > Hi > > I'm trying to use Toke::Parse and would appreciate some advice. > > My html is something like this > > <div id="mainbody"> > <h1>advise you to</h1> > <ul> > > <li> > <a href="/Advice/apples">apples</a> > </li> > > <li> > <a href="/Advice/oranges">oranges</a> > </li> > <li> > <a href="/Advice/pears">pears</a> > </li> > > </ul> > <div id="footer"> > <p class="style1"><span class="siteName">Smartshopper</span> is > provided by the <a href="http://www.fat.gov">FatTrade</a>.</p> > <p><span class="style3 noprint"> > > <a href="http://fat.gov/copyright.html">Copyright</a> > <a href="http://www.fat.gov/disclaim.html">Disclaimer</a> > <a href="http://www.fat.gov/privacy.html">Privacy</a> > </span> > </p> > </div> > </div> > > my toke paser snippet > > while ( $tag = $stream->get_tag("div") ) { > if ($tag->[1]{id} and $tag->[1]{id} eq 'mainbody') { > while ($tag = $stream->get_tag('a')){ > print Dumper $tag; > } > } > } > > my problem > > 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; } Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/