It is better to do this:..... if($object->some_recursive_call > $value){ $value = $object->some_recursive_call; } .....
Or this:..... 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,lPla +ce,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);
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Faster Perl, Good and Bad News
by MrNobo1024 (Hermit) on Aug 09, 2002 at 21:25 UTC | |
by sauoq (Abbot) on Aug 09, 2002 at 22:30 UTC | |
by demerphq (Chancellor) on Aug 09, 2002 at 23:53 UTC | |
by MrNobo1024 (Hermit) on Aug 10, 2002 at 00:04 UTC | |
by demerphq (Chancellor) on Aug 12, 2002 at 09:33 UTC | |
Re: Faster Perl, Good and Bad News
by dws (Chancellor) on Aug 09, 2002 at 22:33 UTC | |
by abitkin (Monk) on Aug 09, 2002 at 22:48 UTC | |
by dws (Chancellor) on Aug 09, 2002 at 23:01 UTC | |
by FoxtrotUniform (Prior) on Aug 10, 2002 at 22:39 UTC | |
by BrowserUk (Patriarch) on Aug 10, 2002 at 23:51 UTC | |
| |
Faster PerlMonks: Good and Bad News
by mirod (Canon) on Aug 10, 2002 at 09:01 UTC | |
Re: Faster Perl, Good and Bad News
by ichimunki (Priest) on Aug 09, 2002 at 21:55 UTC | |
Re: Faster Perl, Good and Bad News
by derby (Abbot) on Aug 09, 2002 at 22:44 UTC | |
Re: Faster Perl, Good and Bad News
by theorbtwo (Prior) on Aug 10, 2002 at 09:43 UTC | |
Re: Faster Perl, Good and Bad News
by simon.proctor (Vicar) on Aug 09, 2002 at 23:28 UTC | |
Re: Faster Perl, Good and Bad News
by petral (Curate) on Aug 10, 2002 at 18:52 UTC | |
Re: Faster Perl, Good and Bad News
by Abigail-II (Bishop) on Aug 12, 2002 at 12:49 UTC |