![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
use MLDBM; # this gets the default, SDBM #use MLDBM qw(DB_File); $dbm = tie %o, MLDBM [..other DBM args..] or die $!;
It works by converting the values in the hash that are references, to their string representation in perl syntax. When using a DBM database, it is this string that gets stored.
It requires the Data::Dumper package, available at any CPAN site.
See the BUGS section for important limitations.
use
time. Nested module names can be specified as ``Foo::Bar''.
Data::Dumper
are used. By default, this is set to ``Dumpxs'', the faster of the two
methods, but only if MLDBM detects that ``Dumpxs'' is supported on your
platform. Otherwise, defaults to the slower ``Dump'' method.
use MLDBM; # this gets SDBM #use MLDBM qw(DB_File); use Fcntl; # to get 'em constants $dbm = tie %o, MLDBM, 'testmldbm', O_CREAT|O_RDWR, 0640 or die $!; $c = [\ 'c']; $b = {}; $a = [1, $b, $c]; $b->{a} = $a; $b->{b} = $a->[1]; $b->{c} = $a->[2]; @o{qw(a b c)} = ($a, $b, $c); # # to see what wuz stored # use Data::Dumper; print Data::Dumper->Dump([@o{qw(a b c)}], [qw(a b c)]);
# # to modify data in a substructure # $tmp = $o{a}; $tmp[0] = 'foo'; $o{a} = $tmp; # # can access the underlying DBM methods transparently # #print $dbm->fd, "\n"; # DB_File method
$mldb{key}{subkey}[3] = 'stuff'; # won't work
Instead, that must be written as:
$tmp = $mldb{key}; # retrieve value $tmp->{subkey}[3] = 'stuff'; $mldb{key} = $tmp; # store value
This limitation exists because the perl TIEHASH interface currently has no support for multidimensional ties.
use MLDBM (DB_File); # be sure it's the new MLDBM use Fcntl; tie %o, MLDBM, 'oldmldbm.file', O_RDWR, 0640 or die $!; for $k (keys %o) { my $v = $o{$k}; if ($v =~ /^\$CrYpTiCkEy/o) { $v = eval $v; if ($@) { warn "Error: $@\twhile evaluating $v\n"; } else { $o{$k} = $v; } } }
Copyright (c) 1995 Gurusamy Sarathy. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
perl(1),
perltie(1),
perlfunc(1)
$CommentsMailTo = "perl5@dcs.ed.ac.uk"; include("syssies_footer.inc");?>