The DB_File module provides tied hash access to BTREE data files, which make it very convenient to search for all keys that fall within a certain range. The documentation doesn't have an example of this, so here's one.
# Input: %btree is already tied to a $DB_BTREE file # $first and $last define the range to search for # It's assumed that the btree uses the default sort order my $db = tied %btree; my $key = $first; my $value; for (my $status = $db->seq($key, $value, R_CURSOR); $status == 0 && $key le $last; $status = $db->seq($key, $value, R_NEXT)) { print "$key = $value\n"; }

Replies are listed 'Best First'.
Re: Range search on a DB_File BTREE
by Fool on the Hill (Acolyte) on Jul 12, 2001 at 20:30 UTC
    This looks really handy as we have to manipulate loads of btrees on a daily basis. It has prompted me to find out loads more about these interesting structures... Thanks!