Next The Perl Hardware Store DC.pm Version 29

Caching

          {  my @fact = ();
             sub factorial {
               my $n = shift;
               return $fact[$n] 
                 if defined $fact[$n];
               $fact[$n] = 
                 ($n == 0 ? 1 
                          : $n * factorial($n-1));
           }
         }


Next Copyright © 2003 M. J. Dominus