title: Using HTML::TreeBuilder::XPath on nested information
body: <p>Imagine an HTML page that is a report with repetitive structure:</p>
  
  <pre><code>&lt;html&gt;
    &lt;body&gt;
      &lt;h1&gt;Big Hairy Report Page&lt;/h1&gt;
  
      &lt;div class="customer"&gt;
        &lt;div class="customer_id"&gt;001&lt;/div&gt;
        &lt;div class="customer_name"&gt;Joe Blough&lt;/div&gt;
        &lt;div class="customer_addr"&gt;123 That Road&lt;/div&gt;
        &lt;div class="customer_city"&gt;Smallville&lt;/div&gt;
        &lt;div class="customer_state"&gt;Nebraska&lt;/div&gt;
        &lt;div class="order_info"&gt;
          &lt;div class="shipping_details"&gt;
            &lt;ul&gt;
               &lt;li&gt;Large crate&lt;/li&gt;
               &lt;li&gt;Fragile&lt;/li&gt;
               &lt;li&gt;Express&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/div&gt;
          &lt;div class="order_item"&gt;Deluxe Hoodie&lt;/div&gt;
          &lt;div class="payment"&gt;35.95&lt;/div&gt;
          &lt;div class="order_id"&gt;000123456789&lt;/div&gt;
        &lt;/div&gt;
        &lt;div class="comment"&gt;StackOverflow rocks!&lt;/div&gt;
      &lt;/div&gt;
  
     &lt;div class="customer"&gt;
       &lt;div class="customer_id"&gt;002&lt;/div&gt;
   ....  and so forth for a list of 150 customers
  </code></pre>
  
  <p>This kind of report page appears often.  My goal is to extract each customer's related information into some reasonable data structure using <a href="https://metacpan.org/module/HTML%3a%3aTreeBuilder%3a%3aXPath" rel="nofollow"><code>HTML::TreeBuilder::XPath</code></a>.</p>
  
  <p>I know to do the basics and get the file read into $tree.  But how can one concisely loop through that tree and get associated clusters of information per each customer?  How, for example, would I create a list of address labels sorted by customer number based on this information?  What if I want to sort all my customer information by state?</p>
  
  <p>I'm not asking for the whole perl (I can read my file, output to file, etc).  I just need help understanding how to ask HTML::TreeBuilder::XPath for those bundles of related data, and then how to dereference them.  If it's easier to express this in terms of an output statement (i.e., Joe Blough ordered 1 Deluxe Hoodie and left 1 comment) then that's cool, too.  </p>
  
  <p>Thank you very much for those of you who tackle this one, it seems a bit overwhelming to me.</p>