git @ Cat's Eye Technologies Dipple / master perl / bdbtest
master

Tree @master (Download .tar.gz)

bdbtest @masterraw · history · blame

#!/usr/bin/perl

# SPDX-FileCopyrightText: Chris Pressey, the original author of this work, has dedicated it to the public domain.
# For more information, please refer to <https://unlicense.org/>
# SPDX-License-Identifier: Unlicense

use strict 'vars', 'refs';
use BerkeleyDB;

my %hash = ();
my $db = tie %hash, 'BerkeleyDB::Hash',
    -Filename => "testDB",
    -Flags    => DB_CREATE;

if ($ARGV[0] eq '-r') {
    my $x = $hash{$ARGV[1]};
    die "not found\n" if not defined $x;
    print "name: $x{name}\n";
    print "date: $x{date}\n";
    exit(0);
}

if ($ARGV[0] eq '-w') {
    my $key = $ARGV[1];
    my $name = $ARGV[2];
    my $date = 0 + $ARGV[3];
    $hash{$key}{name} = $name;
    $hash{$key}{date} = $date;
    print "ok\n";
    exit(0);
}

die "usage\n";