Dear Monks,

I am having a problem with associated tables using the BerkeleyDB module. Here is a snippet of code:

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\' ... "; $table->associate($db, \&key_sub);
The key_sub extracts one field from the record using split, and I want to use that as a secondary index. I have no error messages when the first record is inserted, but when I insert a second record, I get error messages that indicate that the numeric comparison function, and not the ascii comparison function, is being used for the secondary table.
Argument "w61" isn't numeric in numeric comparison (<=>) at /home/Acct +Table.pm line 80. Argument "w60" isn't numeric in numeric comparison (<=>) at /home/Acct +Table.pm line 80.
The line number in the error messages above is the line where the numeric comparison is defined. Is this a bug in the perl BerkeleyDB module, or is it a bug in the db library itself? Is there a work-around for it? Thanks for your help.

In reply to Associated BerkeleyDB table uses wrong compare? by tall_man

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.