in reply to Simple Program Huge Problem
If the program reached the last return statement why is it going to STEP4 and not to the main function? Could anyone tell me what is going out?
#!/usr/bin/perl -w use strict; use Tree::Simple; #use Tree::Simple 'use_weak_refs'; use Data::Dumper; #use Devel::Trace; $Data::Dumper::Indent=1; #$Devel::Trace::TRACE=0; local $|=1; my $CR="\n"; my $WS="-------------------------------------------------------------- +---$CR"; my @array = qw/ 112.75 850.22 100.65 /; #for (my $j=0;$j<1;$j++) # { #always the same code to execute my $i=0; my $tree = Tree::Simple->new("root tree",Tree::Simple->ROOT); printleaf(\$tree); $tree->addChild(Tree::Simple->new("$array[$i]")); printleaf(\$tree->getChild(0)); my @_auxarray=@array; splice(@_auxarray,$i,1); foreach my $elem (@_auxarray) { printleaf(\Tree::Simple->new("$elem",$tree->getChild(0))); } undef @_auxarray; print "${WS}DATA DUMPER: $CR"; print Dumper $tree; print "${WS}"; FULLY_DESTROY($tree); ###########################STEP 3############################ print "${WS}DATA DUMPER: $CR"; print Dumper $tree; #$tree->traverse(sub { my($_tree)=@_; #print (("\t" x $_tree->getDepth()), $_tree->g +etNodeValue(),"\n"); #}); undef $tree; # } <STDIN>; #pause sub printleaf{ my ($_leaf)=$_[0]; print("VALUE: ",$$_leaf->getNodeValue()," | ROOT?: ",$$_leaf->isRo +ot() ? "true" : "false"," | DEPTH: ",$$_leaf->getDepth()," | INDEX: " +,$$_leaf->getIndex(),"$CR"); } sub FULLY_DESTROY{ my ($self)=$_[0]; print ($self->getNodeValue()," "); while(1) { ###########################STEP 4############################ if(!ref($self->{_parent}) && $self->{_parent} eq 'root' && sca +lar(@{$self->{_children}})==0) { $self->{_parent} = undef; print ("called last to end the sub routine$CR"); ###########################STEP 1######################### +### last; } if(defined($self->{_children}) && $self->getChildCount!=0) { print ("childs ",$self->getChildCount(),"$CR"); FULLY_DESTROY($self->getAllChildren()); } #if has no childs saves the father reference my $ref; my $index=$self->getIndex(); print("index ",$index," "); if(($index+1) == ($self->getParent()->getChildCount())) #last +in the branch { print ("childs 0 last in branch$CR"); $ref = \$self->getParent(); $self->{_parent} = undef; @{$$ref->{_children}}=(); FULLY_DESTROY($$ref); } else { print ("childs 0 not last in branch$CR"); $ref = \$self->getSibling($index+1); $self->{_parent} = undef; FULLY_DESTROY($$ref); } } ###########################STEP 2############################ print "end should return to main function$CR$CR"; return; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Simple Program Huge Problem
by crusher (Acolyte) on Nov 09, 2008 at 17:36 UTC | |
by Corion (Patriarch) on Nov 09, 2008 at 17:48 UTC |