Roboz has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Building a data structure - %HoH, %HoA?
by BrowserUk (Patriarch) on Nov 01, 2012 at 12:27 UTC | |
|
Reading your input
by space_monk (Chaplain) on Nov 01, 2012 at 13:21 UTC | |
|
Re: Building a data structure - %HoH, %HoA?
by Jenda (Abbot) on Nov 02, 2012 at 10:18 UTC | |
|
Re: Building a data structure - %HoH, %HoA?
by Anonymous Monk on Nov 02, 2012 at 07:52 UTC | |
|
Re: Building a data structure - %HoH, %HoA?
by Anonymous Monk on Nov 01, 2012 at 23:57 UTC | |
|
Re: Building a data structure - %HoH, %HoA?
by locked_user sundialsvc4 (Abbot) on Nov 02, 2012 at 02:06 UTC |