in reply to Approximate Matching Key

If you use a DBM that uses B-Tree keys instead of hashed keys, then you can use the non-tied methods to do a "less than or equal" search for a key in a manner that will be very efficient.

But for that to work you need to normalize your keys so that they sort properly as strings. For example, pad them with sufficient zeros, store them as pack("N",$key), or preface the key with the number of digits (length($key).".$key" so long as you don't have keys of more than 9 digits).

        - tye (but my friends call me "Tye")

Replies are listed 'Best First'.
Re (tilly) 2: Approximate Matching Key
by tilly (Archbishop) on Apr 07, 2001 at 05:24 UTC
    Actually if you use Berkely DB either through DB_File or BerkeleyDB you can choose the sort order for the BTree, and using the R_CURSOR flag you can have the hash lookup implement the approximate search exactly as requested.
Re: (tye)Re: Approximate Matching Key
by fxia (Novice) on Apr 10, 2001 at 01:33 UTC
    Thanks for the help. But where can I find more documentation on using B-Tree keys? Fred

      In this very thread, here.

      Some more specifics: The DB_File approach looked easier (though I only looked briefly). You want to create a databse in DB_BTREE format with a comparison function that does a numeric compare rather than a string compare. You can then use the R_CURSOR flag the seq() method to get what you want.

              - tye (but my friends call me "Tye")