I am printing a tree based on the contents of an array, where each element has id,name,parentID, and level, where level is the depth of the item in the tree. i.e.:
foo
->bar
-->troz
->narf
where foo is level0, bar is level1 with parent foo, narf is level 1 with parent foo, and troz is level 2 with parent bar. The array is created by
$item{id} = $id;
$item{name} = $name;
$item{level} = $level;
$item{parent} = $parent;
push @list, \%item;
how can I sort @list so that it will print out in the correct tree order? it can be arbitrary depth and the goal is to avoid recursion, both in creating the list and displaying the list. My attempts with an ST and various other closures have failed to create the correct ordering, so far the only successful algorithm involves creating the list via recursion, or building an HoH and recursing over it to build the display, but that doesn't scale very nicely.