reluctant_techie has asked for the wisdom of the Perl Monks concerning the following question:
Represented another way, the path to "D" is A/B/C/.
My goal is to create a subroutine that would return the path to whatever child I passed to the subroutine. So, once again, if I passed "D" to the subroutine, it would return "A/B/C/". I have approached this task by creating two hashes that share the same keys:
I have also created a subroutine to return the value from the "name" hash for the parent of a child:my %name = (1, "A", 2, "B", 3, "C", 4, "D"); my %parent = (1, 0, 2, 1, 3, 2, 4, 3);
I am now uncertain how to create a loop that will keep passing the key of the child's parent to the subroutine until the parent of the parent is "0".sub get_parent_value { my $parent_key = $parent{$key}; my $parent_value = $name{$parent_key}; return $parent_value; }
I would love to see any ideas you all might have on this.
Thanks for your time!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Processing Data in a Tree
by dragonchild (Archbishop) on Jun 26, 2008 at 01:33 UTC | |
|
Re: Processing Data in a Tree
by Limbic~Region (Chancellor) on Jun 26, 2008 at 01:45 UTC | |
|
Re: Processing Data in a Tree
by jethro (Monsignor) on Jun 26, 2008 at 02:35 UTC |