Help for this page

Select Code to Download


  1. or download this
    sub fib {
      croak("…")  if @_ != 1;
    ...
      return $nth if $nth <= 1;
      return fib( $nth - 1 ) + fib( $nth - 2 );
    }
    
  2. or download this
    my $fib_die_msg = 'fib() takes one positive integer as argument, abort
    +ed';
    sub fib {
    ...
      return $nth if $nth <= 1;
      return fib( $nth - 1 ) + fib( $nth - 2 );
    }
    
  3. or download this
    sub fib {
      my($nth = shift) =~ m{^\d+$} and ! @_ or die $fib_die_msg;
      ...
    }
    
  4. or download this
    sub fib {
      my $nth = shift;
    ...
      return $nth if $nth <= 1;
      return fib( $nth - 1 ) + fib( $nth - 2 );
    }