in reply to Re^2: Generating a Hash of Hashes Recursively to Display Database Hierarchy
in thread Generating a Hash of Hashes Recursively to Display Database Hierarchy
I dare say your join is broken and that's what should be fixed. But it's easy to work with it anyway.
You have:
my $data = [ [ 'parent1', 'child1a', 'child2a', undef, ], [ 'parent1', 'child1b', 'child2b', 'child3b',], [ 'parent1', 'child1c', undef, undef,], ];
You want:
my $data = [ [ 'parent1', 'child1a' ], [ 'parent1', 'child2a' ], [ 'parent1', 'child1b' ], [ 'parent1', 'child2b' ], [ 'parent1', 'child3b' ], [ 'parent1', 'child1c' ], ];
Easy! Change
while (my $row = $sth->fetch()) { my ($id, $parent_id) = @$row; ... }
to
while (my $row = $sth->fetch()) { my ($parent_id, @children_ids) = @$row; for my $id (grep defined, @children_ids) { ... } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Generating a Hash of Hashes Recursively to Display Database Hierarchy
by c4onastick (Friar) on Jun 23, 2009 at 16:59 UTC | |
by ikegami (Patriarch) on Jun 23, 2009 at 17:17 UTC |