Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^4: Generating a Hash of Hashes Recursively to Display Database Hierarchy

by c4onastick (Friar)
on Jun 23, 2009 at 16:59 UTC ( #774110=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Generating a Hash of Hashes Recursively to Display Database Hierarchy
in thread Generating a Hash of Hashes Recursively to Display Database Hierarchy

Ah, my apologies! My short hand with $data got a little too short! $data really looks like this:

my $data = [ [ 'parent1', 'child1', 'grand_child1', undef, ], [ 'parent1', 'child2', 'grand_child2', 'great_grand_child1',], [ 'parent1', 'child3', undef, undef,], ];

Or:

my $data = [ [ 'parent1', 'child1' ], [ 'child1', 'grand_child1' ], [ 'parent1', 'child2' ], [ 'child2', 'grand_child2' ], [ 'grand_child2', 'great_grand_child2' ], [ 'parent1', 'child1c' ], ];

But because of our extended table structure, I'm sure how I can (easily) make it look like the second form though.


Comment on Re^4: Generating a Hash of Hashes Recursively to Display Database Hierarchy
Select or Download Code
Re^5: Generating a Hash of Hashes Recursively to Display Database Hierarchy
by ikegami (Pope) on Jun 23, 2009 at 17:17 UTC

    With the top:

    while (my $row = $sth->fetch()) { for (1..$#$row) { my ($parent_id, $id) = @{$row}[$i-1, $i-0]; last if !defined($id); ... } }

    With the bottom:

    while (my $row = $sth->fetch()) { my ($parent_id, $id) = @$row; ... }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://774110]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2014-09-20 15:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (160 votes), past polls