I have a log file which looks like as follows.
Year:2001
State: A
District A
District B
State: B
District A
District B
Year:2002
State: A
District A
District B
State: B
District A
District B
.
.
Year:2012
State: A
District A
District B
State: B
District A
District B
I would like to have a hash of hash such that:
$VAR2 = {'2001' => {
'state A' => { district a
district b
}
'state B' => { district a
district b
}
}
2002' => {
'state A' => { district a
district b
}
'state B' => { district a
district b
}
}
};
I have tried the above logic using 3 nested loops as follows:
foreach my $key (keys %hash) {
foreach my $key2 (keys %{ $hash{$key} }) {
foreach my $key3 (keys %{ $hash{$key}{$key2} }) {
$value = $hash{$key}{$key2}->{$key3};
}
}
}
Please can somebody explain me the procedure to do it. Or atleast inform me if I am going in the write path. Thank you.
You could do something like:
output: