March 2002 Perl Hardware Store 26

5. Caching

Memoizing

        use DB_File;
        tie %h, 'DB_File', "cmyk.db", O_RDWR|O_CREAT, 0666 or die ...;
        use Memoize;
        memoize 'cmyk', SCALAR_CACHE => [ HASH => \%h ];
        for my $r (0 .. 255) {
          for my $g (0 .. 255) {
            for my $b (0 .. 255) {
              cmyk($r, $g, $b);
            }
          }
        }


Next Copyright © 2002 M-J. Dominus