in reply to Re: Passing subroutines as arguments
in thread Passing subroutines as arguments
Interesting... So what's wrong with this? sum_cubes2(1, 3) is returning 1 instead of 36 like it should and giving the warning "Use of uninitialized value in numeric gt (>) at /Users/mvaline/bin/summation line 35."
sub sum { my ($term, $a, $next, $b) = @_; if ($a > $b) { return(0); } else { return( $term->($a) + &sum( $term, ($next->($a)), ($next->( +$b)) ) ); } } sub inc { my ($n) = @_; return( $n + 1 ); } sub sum_cubes2 { my ($a, $b) = @_; return( &sum(\&cube, $a, \&inc, $b) ); }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re:^3 Passing subroutines as arguments
by arturo (Vicar) on May 08, 2003 at 20:24 UTC | |
by mvaline (Friar) on May 08, 2003 at 20:37 UTC |
In Section
Seekers of Perl Wisdom