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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |