Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Using HTML Module

by wstarrs (Acolyte)
on May 22, 2001 at 22:42 UTC ( [id://82341]=perlquestion: print w/replies, xml ) Need Help??

wstarrs has asked for the wisdom of the Perl Monks concerning the following question:

I am using the HTML::TokeParser module to parse thorugh data records and pull out relevant items. I have a particular item tag that has other sub-items nested within, I need to grab the sub items and place them into a hash where the parsed values need to be stored in an array in the hash (basically $hash{filename}{NestedValueArray}. The code I have so far worked fine when there was only one of the nested values specified on the data record, however when more than one is specified it populates the first value and doesn't move to the next, I have tried to debug this loop to no avail, can someone take a look...
if ($item_name eq "Show Link") { $i=0; $temp_token = $p->get_token; while (!(($temp_token->[0] eq "E") && ($temp_token->[1 +] eq "item"))) { if (($temp_token->[0] eq "S") && ($temp_token->[1 +] eq "value")) { $temp_token = $p->get_tag("item"); $temp_dcr{$dcr_name}{Location}[$i] = $p->get_t +rimmed_text("/item"); $i++; } $temp_token = $p->get_token; } $found++; }
Thanks a lot, if you need any more info let me know... Bill

Replies are listed 'Best First'.
Re: Using HTML Module
by chromatic (Archbishop) on May 23, 2001 at 04:32 UTC
    As I read it, the problem is that $temp_token->[1] will never be both 'item' and 'value' at the same time. Anything that passes the while condition can't pass the nested if. Here's one shot at it. I think this is more clear:
    if ($item_name eq "Show Link") { my @elements; while ($temp_token = $p->get_token) { last if $temp_token->[0] eq 'E'; if (($temp_token->[0] eq "S") && ($temp_token->[1] eq "value" +)) { $temp_token = $p->get_tag("item"); push @elements, $p->get_trimmed_text('/item'); } $temp_token = $p->get_token; } $temp_dcr{$dcr_name}{Location} = \@elements; }
    I may be misreading your logic, but it looks a little easier to me.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://82341]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (1)
As of 2024-04-16 18:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found