in reply to Trouble Parsing HTML

An inner $p->get_tag() loop is needed.
use strict; use warnings; use HTML::TokeParser; my $p = HTML::TokeParser->new( *DATA ); while (my $token = $p->get_tag('select')) { my $name = $token->[1]{name} ; my $option_text = ''; while (my $token2 = $p->get_tag('option', '/select')) { last if $token2->[0] eq '/select'; if ( $token2->[0] eq 'option' and $token2->[1]{selected} ) { $option_text = $p->get_trimmed_text(); last; } } print "\$name = '$name', \$option_text = '$option_text'\n"; } __DATA__ <TD style="HEIGHT: 29px"> <select name="cmbPurpose" id="cmbPurpose" tabindex="3"> <option value="CD">Cell Development</option> <option value="MS">Miscellaneous R&amp;D</option> <option value="NP">New Package</option> <option value="NR">Non R&amp;D</option> <option value="PC">New process</option> <option selected="selected" value="PD">New product</option> <option value="SP">Sustaining Product</option> <option value="SW">Software and Platform</option> <option value="TD">Technology Development</option> </select></TD>

Replies are listed 'Best First'.
Re^2: Trouble Parsing HTML
by Rhodium (Scribe) on Jan 29, 2005 at 14:20 UTC
    I think one of the other posters said it best TMTOWTDI.
    However this was the solution that I was looking for. I really appreciate the hand and thanks a ton.

    Thanks again to all posters


    Rhodium

    The seeker of perl wisdom.