use strict;
use warnings;
use BerkeleyDB;
my $home = ".";
my $tableName = "testDB";
my $dbName = "testDex";
my $table = BerkeleyDB::Btree->new(
-Filename => "$home/$tableName/$tableName",
-Compare => sub { my($a, $b) = @_; return $a <=> $b; }, # numeric
-Flags => DB_CREATE,
) or die "Could not open \'$home/$tableName/$tableName\' ... ";
my $db = BerkeleyDB::Btree->new(
-Property => DB_DUP,
-Flags => DB_CREATE,
-Filename => "$home/$tableName/$dbName",
-Compare => sub { my($a, $b) = @_; return $a cmp $b; }, # ascii
) or die "Could not open \'$home/$tableName/$dbName\' ... ";
sub key_sub {
my $pkey = shift;
my $pdata = shift;
$_[0] = (split /\|/,$pdata)[1];
return 0;
}
$table->associate($db, \&key_sub);
$table->db_put(1,"x|w60");
$table->db_put(2,"y|w61");
####
Argument "w60" isn't numeric in numeric comparison (<=>) at hhh.pl line 11.
Argument "w61" isn't numeric in numeric comparison (<=>) at hhh.pl line 11.
Argument "w60" isn't numeric in numeric comparison (<=>) at hhh.pl line 11.
Argument "w61" isn't numeric in numeric comparison (<=>) at hhh.pl line 11.
####
my $digits = qr/^\d+$/;
sub eitherComp {
my($a, $b) = @_;
return $a <=> $b if ($a =~ $digits and $b =~ $digits);
return $a cmp $b;
}
####
count = perl_call_sv(CurrentDB->compare, G_SCALAR);