del#

Delete a key - every value of it, in an R_DUP database - or, with R_CURSOR, the one item the database’s cursor stands on.

Synopsis#

my $status = $db->del($key);
$status = $db->del($key, R_CURSOR);    # $key unused

What you get back#

0 when something was deleted, 1 when the key was not there, -1 for an error. On an array, deleting an element created empty returns -30995 (Berkeley DB’s DB_KEYEMPTY).

Examples#

$h{apple} = 'red';
print $db->del('apple');        # 0
print $db->del('apple');        # 1

Delete one of a key’s duplicates, found with seq:

my ($k, $v) = ('fruit', '');
$db->seq($k, $v, R_CURSOR);     # the key's first value
$db->del($k, R_CURSOR);         # just that one

Edge cases#

  • With R_CURSOR and no cursor set yet, it returns -1.

  • After a delete at the cursor, seq with R_NEXT goes on to the item after the deleted one and R_PREV to the one before. Deleting at the cursor again deletes nothing; on an array it returns -30995.

  • Deleting an array element moves the ones after it down.

  • On a database opened read-only it returns -1, and $DB_File::Error says so.

Differences from upstream#

Fully compatible with upstream. Covered by t/81-xs-native/DB_File/010-phenotype.t.

See also#

  • seq - sets the cursor R_CURSOR deletes at

  • del_dup - deletes one given value of a key