Next | Lightweight Databases | 87 |
tie %hash, 'DB_File', $file, O_CREAT|O_RDWR, 0666, $DB_BTREE;
By default, the ordering is lexicographic:
for (qw(red orange yellow green blue violet)) { $hash{$_} = length; }
print join(" ", keys %hash), "\n";
blue green orange red violet yellow
You may specify an alternative ordering:
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 |