.....
if($object->some_recursive_call > $value){
$value = $object->some_recursive_call;
}
.....
####
.....
my $temp = $object->some_recursive_call;
if($temp > $value){
$value = temp;
}
.....
##
##
.....
my $temp = $object->some_recursive_call;
$value = $temp if $temp > $value;
.....
##
##
# perl
# node:
sub countLeaves{
my $self = shift;
my $ret = 0;
foreach my $item (@{$self->[$node::child]}){
next if ! defined($item);
$ret += $item->countLeaves;
}
$self->[$node::leaves]=$ret;
return $ret;
}
#leaf:
sub countLeaves{
return 1;
}
# calling the Perl function:
$tree->countLeaves;
# C code:
I32 getLeavesInt( SV* root, I32 childPlace, I32 numKeys,
I32 lPlace, I32 wPlace){
I32 i, n, curr;
AV* arr1;
AV* arr2;
SV* child;
if( !SvROK(root)){
return 0;
}
arr1 = (AV*)SvRV(root);
n = av_len(arr1);
curr = 0;
if(n>1){
if(!SvROK(*av_fetch (arr1,childPlace,0))){
return 0;
}
arr2 = (AV*)SvRV(*av_fetch (arr1,childPlace,0));
for(i = 0; i <= numKeys; i++){
if(!(av_fetch(arr2,i,0) == NULL)){
child = (*av_fetch(arr2,i,0));
if(SvROK(child)){
curr += getLeavesInt(child,childPlace,numKeys,lPlace,wPlace);
}
}
}
av_store(arr1,lPlace,(SV*) newSViv(curr));
root=((SV*)arr1);
}else{
if(SvIV(*av_fetch(arr1,wPlace,0))!=0){
curr = 1;
}
}
return curr;
}
SV* getLeaves( SV* root, SV* childPlace, SV* numKeys,
SV* lPlace, SV* wPlace){
I32 ret;
ret = getLeavesInt(root,SvIV(childPlace),SvIV(numKeys),
SvIV(lPlace),SvIV(wPlace));
return newSViv(ret);
}
# calling the c function is:
getLeaves($tree,$node::child,$numKeys,$node::leaves,$leaf::weight);