DBM-Deep
view release on metacpan or search on metacpan
lib/DBM/Deep.pod view on Meta::CPAN
$db->delete("foo"); # for hashes
$db->delete(1); # for arrays
=item * clear()
X<clear>
Deletes B<all> hash keys or array elements. Takes no arguments. No return
value.
$db->clear(); # hashes or arrays
=item * lock() / unlock() / lock_exclusive() / lock_shared()
X<lock>
X<unlock>
X<lock_exclusive>
X<lock_shared>
q.v. L</LOCKING> for more info.
=item * optimize()
X<optimize>
This will compress the datafile so that it takes up as little space as possible.
There is a freespace manager so that when space is freed up, it is used before
extending the size of the datafile. But, that freespace just sits in the
datafile unless C<optimize()> is called.
C<optimize> basically copies everything into a new database, so, if it is
in version 1.0003 format, it will be upgraded.
=item * import()
X<import>
Unlike simple assignment, C<import()> does not tie the right-hand side. Instead,
a copy of your data is put into the DB. C<import()> takes either an arrayref (if
your DB is an array) or a hashref (if your DB is a hash). C<import()> will die
if anything else is passed in.
=item * export()
X<export>
This returns a complete copy of the data structure at the point you do the export.
This copy is in RAM, not on disk like the DB is.
=item * begin_work() / commit() / rollback()
These are the transactional functions. L</TRANSACTIONS> for more information.
=item * supports( $option )
X<supports>
This returns a boolean indicating whether this instance of DBM::Deep
supports that feature. C<$option> can be one of:
=over 4
=item * transactions
X<translation>
=item * unicode
X<unicode>
=back
=item * db_version()
X<db_version>
This returns the version of the database format that the current database
is in. This is specified as the earliest version of DBM::Deep that supports
it.
For the File back end, this will be 1.0003 or 2.
For the DBI back end, it is currently always 1.0020.
=back
=head2 Hashes
For hashes, DBM::Deep supports all the common methods described above, and the
following additional methods: C<first_key()> and C<next_key()>.
=over
=item * first_key()
X<first_key>
Returns the "first" key in the hash. As with built-in Perl hashes, keys are
fetched in an undefined order (which appears random). Takes no arguments,
returns the key as a scalar value.
my $key = $db->first_key();
=item * next_key()
X<next_key>
Returns the "next" key in the hash, given the previous one as the sole argument.
Returns undef if there are no more keys to be fetched.
$key = $db->next_key($key);
=back
Here are some examples of using hashes:
my $db = DBM::Deep->new( "foo.db" );
$db->put("foo", "bar");
print "foo: " . $db->get("foo") . "\n";
$db->put("baz", {}); # new child hash ref
$db->get("baz")->put("buz", "biz");
print "buz: " . $db->get("baz")->get("buz") . "\n";
my $key = $db->first_key();
while ($key) {
print "$key: " . $db->get($key) . "\n";
$key = $db->next_key($key);
}
if ($db->exists("foo")) { $db->delete("foo"); }
( run in 0.733 second using v1.01-cache-2.11-cpan-39bf76dae61 )