Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Specifying two compare subroutines using db_btree

by traxlog (Scribe)
on Aug 18, 2003 at 16:10 UTC ( [id://284620]=perlquestion: print w/replies, xml ) Need Help??

traxlog has asked for the wisdom of the Perl Monks concerning the following question:

G'day Monks. Help requested! I'm working on a calendar slash address book program at the moment and would like to use 2 db_btree DB's- one for the calendar (which would use numeric sorting) and one for the names/addresses (using an alpha routine for the sort). Ideally I'd like both DB's tied at the same time. Problem is, specifying the sort affects both tied DB's. Anyone know a workaround? Thanks.
  • Comment on Specifying two compare subroutines using db_btree

Replies are listed 'Best First'.
Re: Specifying two compare subroutines using db_btree
by l2kashe (Deacon) on Aug 18, 2003 at 18:51 UTC

    Off the cuff, if I am understanding you right

    tie(my %cal, etc, etc, etc) or die "Cant tie cal: $!\n"; tie(my %addr, etc, etc, etc) or die "Cant tie addr: $!\n"; @sorted_cal_keys = sort { $a <=> $b } keys %cal; @sorted_adrr_keys = sort { $a cmp $b } keys %addr;

    You didnt specify any particular relation between the 2 data sets, so there is no better way to correlate them at this point. You cant sort on both sets at the same time unless you're key's name maps to its data structure.. ala

    tie(my %cal, etc) or die "cal: $!\n"; tie(my %addr, etc) or die "addr: $!\n"; $cal{"cal_$key"} = $cal_value; $addr{"addr_$key"} = $addr_value; # later for ( sort { $a <=> $b || $a cmp $b } keys %cal, keys %addr) ) { if (m/^cal/) { # its from the calendar } elseif ( m/^addr_/ ) { # from the address book } else { # where did this come from? } }

    use perl;

Re: Specifying two compare subroutines using db_btree
by PodMaster (Abbot) on Aug 19, 2003 at 09:45 UTC
    Let me guess, you're using $DB_BTREE? There is only one $DB_BTREE, but there is nothing stopping you from creating two DB_File::BTREEINFO objects.
    my $one = DB_File::BTREEINFO->new(); my $two = DB_File::BTREEINFO->new();
    update: I almost forgot, `perldoc DB_File' ;)

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

Re: Specifying two compare subroutines using db_btree
by traxlog (Scribe) on Aug 19, 2003 at 14:17 UTC
    Thanks for sharing your wisdom Podmaster! I was indeed using $DB_BTREE. I'm new in the field of objects, that's probably why it slipped past me in the perldoc DB_File (oh believe me.... I've read that one a hundred times!).

    Much appreciated.

    traxlog.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://284620]
Approved by valdez
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-04-16 03:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found