in reply to Re: recursive algorithm
in thread recursive algorithm
This works without a warning
sub evalRna { my ( $left, $right ) = @_; my %bonds = ( GU => 1, UG => 1, AU => 2, UA => 2, CG => 3, GC = +> 3 ); my $numBonds = $bonds{ $bases[$left] . $bases[$right] }; my $level = 0; my $new_left = $left; my $numRna; for ( my $i = $left + 1 ; $i <= $right ; $i++ ) { $level-- if ( $structure[$i] eq ')' ); if ( $level == 0 ) { if ( $structure[$i] eq ')' ) { if ( $numRna = evalRna( $new_left, $i ) ) { $numBonds += $numRna; } } $new_left = $i; } $level++ if ( $structure[$i] eq '(' ); } return $numBonds; }
As you can see, I made some changes for better reading experience. The only change needed is to check if evalRna() returns undef. This caused your warnings. Maybe the return value undef is not, what your intention was.
|
|---|