On Dec 14, 2006, at 3:05 PM, Michael G Schwern wrote:

Matisse Enzer wrote:
   sub complexity_of_six {
       my $bar = shift;
       my $total = 0;
       my $type = ref $bar;
       if ( ! $type ) {
           $total = $bar;
       }
       elsif ( $type eq 'ARRAY' ) {
           foreach my $baz ( @{$bar} ) {
               $total += $baz;
           }
       }
       else {
           confess("Don't know how to handle refs to $type");
       }
       return $total;
   }

I'm missing something, I only count 3 paths. if, elsif and else. The confess() might count (die/throw exception) but its the only path through the else. Same with the loop, its the only path through the elsif.


I over-simplified my explanation. It's not exactly paths-through-the- code.

The complexity "points" in that example are:

   1 for the subroutine itself.
   1 for the "if"
   1 for the ! logic operator in the if condition
   1 for the elsif
   1 for the "ne" logic operator in the elsif condition
   1 for the else
  ----
   6 total


-------------------------------------------------------
Matisse Enzer <[EMAIL PROTECTED]>
http://www.matisse.net/  - http://www.eigenstate.net/



Reply via email to