Article 6964 of comp.lang.perl:
Xref: feenix.metronet.com comp.lang.perl:6964
Path: feenix.metronet.com!news.utdallas.edu!corpgate!crchh327.bnr.ca!crchh342.bnr.ca!not-for-mail
From: lhmaddox@bnr.ca (Ren Maddox)
Newsgroups: comp.lang.perl
Subject: Re: Mergeing Perl dbm databases
Date: 18 Oct 1993 17:16:54 -0500
Organization: Bell-Northern Research, Richardson, TX
Lines: 79
Message-ID: <29v4km$p1f@crchh342.bnr.ca>
References: <3298@deadmin.ucsd.edu>
NNTP-Posting-Host: crchh342.bnr.ca

In article <3298@deadmin.ucsd.edu>,
Booker C. Bense <bense@heart3.ucsd.edu> wrote:
>- I need to write a simple database merge program using perl 
>databases. I used the gnu gdbm libraries so I should be able 
>to open more than one dbm file. If anyone has done this I'd 
>appreciate some examples. 
>
>- Thanks 
>
>- Booker C. Bense : benseb@sdsc.edu

Nothing fancy, but it works for me....

Ren

---- Cut Here ----
#!/bnr/bootleg/bin/perl -- # -*- PERL -*-
# Catch for sh/csh on systems without #! ability.
eval '(exit $?0)' && eval 'exec /bnr/bootleg/bin/perl -S $0 ${1+"$@"}'
& eval 'exec /bnr/bootleg/bin/perl -S $0 $argv:q'
if $running_under_some_other_shell;

# dbmmerge, v1.0, by Ren Maddox <lhmaddox@bnr.ca>
$name = "dbmmerge";
$ver = "1.0";

# v1.0, 1993 April 13     -- initial version

require 'newgetopt.pl';

sub usage {
    print STDERR <<USAGE;

Usage: $script [-h] [-v] <dbmoutfile> <dbminfiles>

       -h                     help (this message)
       -v                     verbose
       <dbmoutfile>           dbm file to merge into
       <dbminfiles>           list of dbm files to merge (without .dir or .pag)

USAGE
}

sub vprint {
    print STDERR @_ if $opt_v;
}

&NGetOpt("h", "v");

($script = $0) =~ s,.*/,,;

&vprint("$0 is version $ver of $name\n");
&usage, exit if $opt_h || @ARGV < 2;

$dbmout = shift;
&vprint("Opening dbm file $dbmout\n");
dbmopen(%dbmout, $dbmout, 0644)
    || die "\n$script: Could not open $dbmout for writing\n\n";

foreach $dbmfile (@ARGV) {
    &vprint("Opening dbm file $dbmfile\n");
    dbmopen(%dbmtemp, $dbmfile, undef)
	|| die "\n$script: Could not open $dbmfile\n\n";
    &vprint("Merging $dbmfile into $dbmout\n");
    foreach $key (keys %dbmtemp) {
	$dbmout{$key} = $dbmtemp{$key};
    }
    &vprint("Closing $dbmfile\n");
    dbmclose(%dbmtemp);
}

&vprint("Closing $dbmout\n");
dbmclose(%dbmout);
---- Cut Here ----
-- 
----------------------------------------------------------------------
Nothing I say really means anything anyway....              Ren Maddox
Email address ---------------------------------------> lhmaddox@bnr.ca



