Next Lightweight Databases 83

Ordered Hashes

     tie %hash, 'DB_File', $file, O_CREAT|O_RDWR, 0666, $DB_BTREE;
     for (qw(red orange yellow green blue violet)) {
        $hash{$_} = length;
     }
     print join(" ", keys %hash), "\n";
     blue green orange red violet yellow
     use DB_File;
     my $rev_btree = DB_File::BTREEINFO->new();
     $rev_btree->{compare} = 
       sub { 
         my ($a, $b) = @_; 
         reverse($a) cmp reverse($b) 
       };
     tie %hash, 'DB_File', $file, O_CREAT|O_RDWR, 0666, $rev_btree;
     red orange blue green violet yellow


Next Copyright © 2003 M. J. Dominus