March 2002 Perl Hardware Store 23

5. Caching

        sub cmyk {
          my ($r, $g, $b) = @_;
          my ($c, $m, $y) = (1-$r, 1-$g, 1-$b);
          my $k = $c < $m ? ($c < $y ? $c : $y)
                          : ($m < $y ? $m : $y);  # Minimum
          for ($c, $m, $y) { $_ -= $k }
          [$c, $m, $y, $k];     
        }


Next Copyright © 2002 M-J. Dominus