bageler has asked for the wisdom of the Perl Monks concerning the following question:
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 byfoo ->bar -->troz ->narf
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.$item{id} = $id; $item{name} = $name; $item{level} = $level; $item{parent} = $parent; push @list, \%item;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: group based array sort
by Trimbach (Curate) on Feb 19, 2004 at 20:07 UTC | |
Re: group based array sort
by artist (Parson) on Feb 19, 2004 at 20:23 UTC | |
by bageler (Hermit) on Feb 19, 2004 at 21:52 UTC | |
by Limbic~Region (Chancellor) on Feb 19, 2004 at 22:59 UTC | |
by bageler (Hermit) on Feb 20, 2004 at 00:05 UTC | |
Re: group based array sort
by Limbic~Region (Chancellor) on Feb 19, 2004 at 19:55 UTC | |
by benn (Vicar) on Feb 19, 2004 at 20:22 UTC | |
Re: group based array sort
by ysth (Canon) on Feb 19, 2004 at 21:03 UTC |