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

Hello monks

Is there a simple way of merging four dbm files into 1 dbm?

I have the dbm files...

is_New_Eng ps_New_Eng ses_New_Eng ss_New-Eng

And I just want to merge the contents of these into another dbm called all_New_Eng?

Is there a quick way to do this (some magic module?) or should I open them all, read through each hash bit by bit, copying the data into the new file as I go?

Ideas?

Thanks

M

Please don't give me a hard time about using dbms instead of tie. I'm very happy using dbms for this small application :)

Replies are listed 'Best First'.
Re: Merging DBM files?
by perrin (Chancellor) on Oct 15, 2002 at 20:35 UTC
    Open all your dbms, and then:
    %new_dbm = (%is_New_Eng, %ps_New_Eng, %ses_New_Eng, %ss_New-Eng);
    And yes, you should use the tied interface to open your dbm files.
Re: Merging DBM files?
by tomhukins (Curate) on Oct 16, 2002 at 10:36 UTC
    If you use perlfunc:tie, you can treat DBM files as hashes, as other monks have already mentioned. The way to deal with this depends on exactly what you want to achieve. Read the replies to Merging hashes and Merge multiple hashes if you're not already aware of how merging hashes might cause problems. You might find Hash::Merge useful.
Re: Merging DBM files?
by nothingmuch (Priest) on Oct 15, 2002 at 20:30 UTC
    Iterating through the hashes will be pretty cheap in terms of programmer efficiency.
    consider the following:
    tie my %new,'Your::DBM::Module','all_New_Eng'; my ($key,$val); foreach my $dbm (qw(is_New_Eng ps_New_Eng ses_New_Eng ss_New_Eng)){ tie my %old,'Your::DBM::Module',$dbm; $new{$key} = $val while(($key,$val) = each %old); }
    That's all there's to it

    -nuffin
    zz zZ Z Z #!perl