# the nested array refs my $tree = [ 'Root', [ 'Child1', [ 'GrandChild1', 'GrandChild2' ], 'Child2' ] ]; # the nested hash references my $tree = { 'Root' => { 'Child1' => { 'GrandChild1' => {}, 'GrandChild2' => {} }, 'Child2' => {} } }; #### # using arrays where # the array index is # the id refered to by # the parent_id my $tree = [ # parent_id, node [ undef, 'Root' ], [ 0, 'Child1' ], [ 0, 'Child2' ], [ 1, 'GrandChild1' ], [ 1, 'GrandChild2' ] ]; # using hashes in a similar manner my $tree = [ { id => 0, parent_id => undef, node => 'Root' }, { id => 1, parent_id => 0, node => 'Child1' }, { id => 2, parent_id => 0, node => 'Child2' }, { id => 3, parent_id => 1, node => 'GrandChild1' }, { id => 4, parent_id => 1, node => 'GrandChild2' } ];