I am having some issues parsing files and reading data into my hash. I am using the HTML::TokeParser module and here is what I am trying to do, I have a file set up like this:
<Item Name="Whatever"> <replicant field> <NestedItem1> <Value1 = "One"> <NestedItem2> <value2 = "Two"> <End replicant> <End "whatever" item>
Now what I need is the parsing routine to look inside the main Item (Whatever in this case) and then retrieve the values from the nested items and put them into a value array inside a hash key (i.e.  %hash{Name}{ValueArray}) I have tried a few different setups and I cannot seem to get it right, it appears to work ok if only one of the nested items has a value (they are from checkboxes) however if they both have a value the program reads the first one into the array and stops. Another issue is the fact that I am having trouble regulating the loops to only look inside this main item. Here is two samples of things I have tried, any suggestions would be appreciated:
if ($item_name eq "LinkLocation") { $i = 0; $temp_token = $p->get_token; while (!($temp_token->[0] eq "E") && ($i < 3)) { if (($temp_token->[1] eq "item")) { $temp_dcr{$dcr_name}{Location}[$i] = $p->get_trimmed_text("/va +lue"); $i++; } $temp_token = $p->get_token; } $found++; }
AND
if ($item_name eq "Show Link") { $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" +)) { for ($i=0;$i<2;) { $temp_token = $p->get_tag("item"); $temp_dcr{$dcr_name}{Location}[$i] = $p->get_trimmed_text( +"/item"); $i++; } $temp_token = $p->get_token; } } $found++; }
Thanks, Bill

In reply to Parsing Issues by wstarrs

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.