Christopher J Bottaro wrote:
> 
> just for practice, i made a class BinaryTree.  its just a blessed reference to
> a hash that contains two things:  size and root.  root gets assigned to a
> BinaryTree::Node which is just a bless reference containing: key, value,
> left, right.
> 
> perl deallocates according to reference counts.  so if i want "destory" my
> tree structure, i'd have to make sure there are no references to any of the
> BinaryTree::Node's, right?  something like this...
> 
> $my pr_clear;
  ^
You have the '$' in the wrong place, it should be:

my $pr_clear;


> $pr_clear = sub {
>         my $p = shift(); # parent node
>         my $w = shift(); # which child of the parent
>         my $n = shift(); # child node
>         if ($n != undef)        {

You cannot use undef in a comparison, use the defined function to
determine if a scalar is defined or not.

          if ( not defined $n ) {


>                 this->$pr_clear($n, "left", $n->left());
                        ^
>                 this->$pr_clear($n, "right", $n->right());
                        ^
>                 $p->$w(undef);
                      ^
You have the '$' in the wrong place, it should be:

                  $this->pr_clear($n, "left", $n->left());
                  $this->pr_clear($n, "right", $n->right());
                  $p->w(undef);


>         }
> }
> 
> sub clear()     {
>         this->$pr_clear(this->{root}, "left", this->{root}->left());
                ^                              ^
>         this->$pr_clear(this->{root}, "right", this->{root}->right());
                ^                               ^
>         this->{root} = undef;
         ^
You have the '$' in the wrong place, it should be:

          $this->pr_clear(this->{root}, "left", $this->{root}->left());
          $this->pr_clear(this->{root}, "right",
$this->{root}->right());
          $this->{root} = undef;

If you want to remove the key 'root' then use delete().  

          delete $this->{root};


> }



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to