Perl Monks, I'm having trouble building a data structure that I can easily retrieve information from later in my code. Given a delimited data file like so:

team_1, location_2, tool_1, 4 team_3, location_1, tool_3, 3 team_2, location_3, tool_3, 2 team_2, location_4, tool_2, 5 team_2, location_4, tool_5, 3

Each team can be in one or more location with one or more tool type. The 4th field is the number of tools. I'd like to eventually generate XML with the following format:

<ToolLocations> <ToolLocation> <LocationName>location_4</LocationName> <ToolList> <Tool> <ToolName>tool_2</ToolName> <ToolNum>5</ToolNum> </Tool> <Tool> <ToolName>tool_5</ToolName> <ToolNum>3</ToolNum> </Tool> </ToolList> </ToolLocation> </ToolLocations>

I believe I need to make a hash of team containing an array of (unique)location containing an array of tools and their number. Or maybe a hash of hashes of hashes?
I've been trying just about every permutation I can think of for days. This seems to work for building one without error, but it doesn't seem right:

(my $team, my $loc, my $tool, my $amt) = (split /[,]/)[1,2,3,4]; $status{$team}{$loc}{$tool}{amt} = $amt;

How would you deal with this? Thanks.


In reply to Building a data structure - %HoH, %HoA? by Roboz

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.