I have two excel files. The first excel file is like this:
12 A P1
23 B P5
24 C P2
15 D P1
06 E P5
The second excel file is like this:
06 100
23 20
06 200
06 95
23 05
24 18
I want to generate the following data structure
$VAR1 = {
'P5' => {
'E' => '06' => [100, 200, 95]
'B' => '23' => [20, 1000, 05, 30]
},
'P2' => {
'C' => '24' => [18, 23, 2300, 3456]
},
'P1' => {
'A' => '12' => [24, 25, 3200, 5668]
'D' => '15' => [168]
}
};
The first excel file enables me to generate the following data structure.
$VAR1 = {
'P5' => {
'E' => '06',
'B' => '23'
},
'P2' => {
'C' => '24'
},
'P1' => {
'A' => '12',
'D' => '15'
}
};
What I did for implementing the above partial structure from the first excel file is as follows:
my %Var1;
for my $i (1 .. $row1)
{
# for simplicity, I just keep the main part to building this hash chain
$Var1{$column3}->{$column2} = {$column1};
}
Here $column3 relates to p1, p2, etc; $column2 relates to E, B, etc and $column1 relates to 06,23,24,etc. The arrays associated with $column1 will be extracted from the second excel file.
My question is how to iterate through this partially finished hash %Var1, and for each key, like 06, to push 100 into it while traversing the second excel file.
So, assuming (what im calling the numeric key ( the ’06’ in this example ) ) is unique then perhaps a function which returns the arrayref:
If the numeric key isn’t found the function will return undef. Also if the numeric key isn’t unique then this won’t work – because it will return the first nkey it finds.