zioigor has asked for the wisdom of the Perl Monks concerning the following question:
Bowing to higher level of knowledge,
I am working with solid-rock DB_File module, but something cracked my faith: i tried to ovverride $DB_BTREE->{'compare'}
routine with a String::Approx 'adist' one.
Belief and RTFM suggested to create a 'callback' with an easy template, something like ...
"hey man these are 2 parameters, do some kind of comparison and give me back -1, 0 or 1" as the 'cmp' example on documentation..."
so, after checking out the only working example routine with case-insensitive comparison on manual, i tried mine:
- all data seem to fit
BUT
when i try to read out key/value pairs, i got "undef" on values for which comparison function returned -1.
Any clue on how to make a Compare function different from the one on manual?
many prayers are rising towards the Monastery
thanks igor
- .db file gets created and i checked the binaries# ------------------------- sub DBFile_Compare_Distance #-------------------------- { my ($k1, $k2) = @_ ; my $dist = adist ( uc $k1 , uc $k2 ); my $val = undef; if( $dist < -1 ) { $val = -1; } elsif( $dist > 1 ) { $val = 1; } else { $val = 0; } $val; }
- all data seem to fit
BUT
when i try to read out key/value pairs, i got "undef" on values for which comparison function returned -1.
Any clue on how to make a Compare function different from the one on manual?
many prayers are rising towards the Monastery
thanks igor
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: looking for inspiration on 'compare'
by fizbin (Chaplain) on Mar 03, 2005 at 14:07 UTC | |
Re: looking for inspiration on 'compare'
by PodMaster (Abbot) on Mar 03, 2005 at 08:19 UTC | |
by zioigor (Initiate) on Mar 03, 2005 at 08:36 UTC | |
by PodMaster (Abbot) on Mar 03, 2005 at 08:52 UTC | |
by zioigor (Initiate) on Mar 03, 2005 at 10:40 UTC | |
Re: looking for inspiration on 'compare'
by jZed (Prior) on Mar 03, 2005 at 14:42 UTC |
Back to
Seekers of Perl Wisdom