| Next | Lightweight Databases | 97 | 
For a user-defined comparison, 'identical' keys might not be exactly the same
Suppose the comparison is case-insensitive:
     my $my_btree = DB_File::BTREEINFO->new();
     $my_btree->{flags} = R_DUP;
     $my_btree->{compare} = sub { lc $_[0] cmp lc $_[1] };
     tie %hash, 'DB_File', $file, O_CREAT|O_RDWR, 0666, $my_btree;
Then Red, red, and RED are all considered 'the same'
     for (['Red', 'apple'], ['red', 'cherry'], 
          ['RED', 'strawberry'], ['blUe', 'grape']) {
        my ($key, $value) = @$_;
        $hash{$key} = $value;
     }
Only the first of these three is actually stored
The hash interface will report the duplicate keys:
     print join(" ", keys %hash), "\n";
     blUe Red Red Red
| Next |  | Copyright © 2003 M. J. Dominus |