=head1 SYNOPSIS
- my $db = tie my %hash, 'DBM', ...;
+ $db = tie %hash, 'DBM', ...
- my $old_filter;
$old_filter = $db->filter_store_key ( sub { ... } );
$old_filter = $db->filter_store_value( sub { ... } );
$old_filter = $db->filter_fetch_key ( sub { ... } );
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\0"} = "$value\0" ;
+ $hash{"$key\0"} = "$value\0";
Similarly the NULL needs to be taken into account when you are considering
the length of existing keys/values.
use Fcntl;
my %hash;
- my $filename = '/tmp/filt';
+ my $filename = "filt";
unlink $filename;
my $db = tie(%hash, 'SDBM_File', $filename, O_RDWR|O_CREAT, 0640)
sub { no warnings 'uninitialized'; s/\0$// } );
$db->filter_store_value( sub { $_ .= "\0" } );
- $hash{abc} = 'def';
- my $a = $hash{ABC};
+ $hash{"abc"} = "def";
+ my $a = $hash{"ABC"};
# ...
undef $db;
untie %hash;
a DBM database it always writes the key and value as strings. So when
you use this:
- $hash{12345} = 'something';
+ $hash{12345} = "something";
the key 12345 will get stored in the DBM database as the 5 byte string
"12345". If you actually want the key to be stored in the DBM database
use warnings;
use DB_File;
my %hash;
- my $filename = '/tmp/filt';
+ my $filename = "filt";
unlink $filename;
my $db = tie %hash, 'DB_File', $filename, O_CREAT|O_RDWR, 0666, $DB_HASH
or die "Cannot open $filename: $!\n";
- $db->filter_fetch_key ( sub { $_ = unpack('i', $_) } );
- $db->filter_store_key ( sub { $_ = pack ('i', $_) } );
- $hash{123} = 'def';
+ $db->filter_fetch_key ( sub { $_ = unpack("i", $_) } );
+ $db->filter_store_key ( sub { $_ = pack ("i", $_) } );
+ $hash{123} = "def";
# ...
undef $db;
untie %hash;