RL has asked for the wisdom of the Perl Monks concerning the following question:

Hi all!

I'm trying to setup a partial match on keys of a DB_File accessed DBM-database.

I've followed the instructions given in the DB_File docs
http://perldoc.perl.org/DB_File.html#Matching-Partial-Keys

Everything working as advertised. Only I would like to get a partial match not only starting at the beginning of the key but find matches which occur anywhere in the key.

For example I've tried to match 'use' which is a part of 'mouse' in the given example.

Is there any trick to allow this sort of matching? Am I asking for too much on the partial matching? :-)

Any input appreciated.
Thx for reading.
RL
  • Comment on DB_BTREE partial matches anywhwere in the key?

Replies are listed 'Best First'.
Re: DB_BTREE partial matches anywhwere in the key?
by diotalevi (Canon) on Apr 30, 2007 at 17:39 UTC

    Btree partial matching works by starting at the beginning string and using each character as a lookup to decide which portions of the database are potentially relevant. This search only works when its done starting at the beginning. You can't get your access pattern from this feature.

    ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Re: DB_BTREE partial matches anywhwere in the key?
by jZed (Prior) on Apr 30, 2007 at 18:14 UTC
    This is probably more overhead than you want, but using DBI with DBD::DBM (comes with DBI but you need to add SQL::Statement for richer SQL) you can treat your database as an, um, database, and use the LIKE operator to match the records you want with SQL. DBD::DBM can work with DB_File or with BerkeleyDb.
      Thanks for the hint.
      The point is, I'm trying to build a system using only core modules and DBM databases.
      I've done similiar with flat files and with SQL.
      It's sort of a challenge to find a reasonable way to go with DBM and core modules.

      Thx again esp. for pointing to SQL::Statement - learned something new again.