<?xml version="1.0" encoding="windows-1252"?>
<node id="993631" title="Re: recursive creation of attached objects?" created="2012-09-14 00:06:00" updated="2012-09-14 00:06:00">
<type id="11">
note</type>
<author id="879250">
remiah</author>
<data>
<field name="doctext">
&lt;p&gt;
Hello. &lt;br&gt;&lt;br&gt;
You return nothing at recursive call. But, at first, you will see lots of warnings if you put use strict and use warnings for your code... &lt;br&gt;&lt;br&gt;
It maybe like this.
&lt;code&gt;
{
package bin_tree;
use strict;
use warnings;

sub new{
    my $class=shift;
    my $self={value=&gt;undef, a=&gt;undef, b=&gt;undef}; #make our object as an anonymous hash with keywords but no values yet, that way the a an
    $self-&gt;{value}=0;
    bless $self, $class; #make object
    return $self; #return object
}
sub populate{
    my($self, $depth)=@_;
    return if(! $depth);

    $self-&gt;{a} = populate( bin_tree-&gt;new() , $depth -1 );
    $self-&gt;{b} = populate( bin_tree-&gt;new() , $depth -1 );
    return $self;
}
1;
} #end bin_tree

package main;
use strict;
use warnings;

#try to create a three node deep binary tree
my $bintree = bin_tree-&gt;new();
$bintree-&gt;populate(3);
use Data::Dumper;
print Dumper $bintree;
&lt;/code&gt;
Moose has [http://search.cpan.org/~doy/Moose-2.0603/lib/Moose/Cookbook/Basics/BinaryTree_AttributeFeatures.pod|"Recipe 3"] for Binary Tree. It is far more advanced.
&lt;/p&gt;</field>
<field name="root_node">
993605</field>
<field name="parent_node">
993605</field>
</data>
</node>
