perldbmfilter (1) Linux Manual Page
NAME
perldbmfilter – Perl DBM Filters
SYNOPSIS
$db = tie % hash, 'DBM', ... $old_filter = $db->filter_store_key(sub{...});
$old_filter = $db->filter_store_value(sub{...});
$old_filter = $db->filter_fetch_key(sub{...});
$old_filter = $db->filter_fetch_value(sub{...});
DESCRIPTION
The four "filter_*" methods shown above are available in all the DBM modules that ship with Perl, namely DB_File, GDBM_File, NDBM_File, ODBM_File and SDBM_File.
Each of the methods works identically, and is used to install (or uninstall) a single DBM Filter. The only difference between them is the place that the filter is installed.
To summarise:
filter_store_key- If a filter has been installed with this method, it will be invoked every time you write a key to a DBM database.
filter_store_value- If a filter has been installed with this method, it will be invoked every time you write a value to a DBM database.
filter_fetch_key- If a filter has been installed with this method, it will be invoked every time you read a key from a DBM database.
filter_fetch_value- If a filter has been installed with this method, it will be invoked every time you read a value from a DBM database.
You can use any combination of the methods from none to all four.
All filter methods return the existing filter, if present, or "undef" if not.
To delete a filter pass "undef" to it.
The Filter
When each filter is called by Perl, a local copy of $_ will contain the key or value to be filtered. Filtering is achieved by modifying the contents of $_. The return code from the filter is ignored.
An Example: the NULL termination problem.
DBM Filters are useful for a class of problems where you always want to make the same transformation to all keys, all values or both.
For example, consider the following scenario. You have a DBM database that you need to share with a third-party C application. The C application assumes that all keys and values are NULL terminated. Unfortunately when Perl writes to DBM databases it doesn’t use NULL termination, so your Perl application will have to manage NULL termination itself. When you write to the database you will have to use something like this:
$hash{"$key
