Your source of error has been identified by others, ie., the token parser is not scoped/recursive, and your inner loop looking for options caused side effect on the outer loop, which exited prematurely.
Being the HTML Token Parser, it's good at parsing tokens. :-) You could rewrite your loop using the token parser, instead of the get_tag.
...
while (my $token = $parser->get_token)
{
next unless $token->[1] =~ /(?:select|input|textarea)/;
if ($token->[0] eq 'S') # start tag
{
$count++;
my $tag = $token->[1];
my $name = $token->[2]{name}; # fetch name of input
my $value = $token->[2]{value};
my $maxlength = $token->[2]{maxlength};
my $required = $token->[2]{required};
my $allowed;
if ($tag eq 'select')
{
while (my $option = $parser->get_token)
{
last if $option->[0] eq 'E' && $option->[1] eq 'select';
next unless $option->[0] eq 'S' && $option->[1] eq 'option';
push @{$allowed}, $option->[2]{value};
}
} else {
$allowed = [ $token->[2]{allowed} ];
}
$DEBUG && print "$count\t$tag\t$name\t\n";
if ($tag eq 'select') {
print Dumper($allowed);
}
}
...
}
And the debug output shows:
1 input text1
2 textarea textarea1
3 input radio1
4 input radio1
5 input check1
6 input check1
7 select list1
$VAR1 = [
'1',
'2',
'3'
];
8 input text2
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.