I need to read in a plain text file representing an arbitrary hierarchy of elements, where the elements are separated by newlines and the hierarchy structure is defined by tabs, like so:
foo
sub1
sub2
sub21
sub22
bar
camel
I would like to have my program generate the following hash tree from that text data:
my $hash_tree = {
foo => {
sub1 => '',
sub2 => {
sub21 => '',
sub22 => ''
}
},
bar => {
camel => ''
}
}
I have contemplated various recursive and iterative approaches to this problem, but have yet to come up with
anything viable (ergo no code here).
Has anyone here done something similar before, or have a good idea of how to do it?
Thanks in advance,
Bill
PS: if it makes a difference in how you would respond to such a question, I'll tell you that I'm proficient with C/C++, but am a relative beginner with Perl.