in reply to Processing Data in a Tree
That way keys %parent would give you a list of all names (as substitute for the names hash). If you don't need that, the hash entry ('A',0) could be dropped and not exists $parent($x) would be true if $x has no parent.my %parent = ('A',0,'B','A','C',B','D','C';
But if you need the numbers, there is still one thing I would change: get_parent_value should return the number of the parent and not the name (as long as it is fed the number of the child and not the name). It is not good design to continually switch between different representations of the same thing. You're sure to mix them up eventually and get a number when you expected a name or vice versa in your code
By the way, your sub is missing a first line my ($key)=@_;
|
|---|