<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">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: &lt;29v4km$p1f@crchh342.bnr.ca&gt;
References: &lt;3298@deadmin.ucsd.edu&gt;
NNTP-Posting-Host: crchh342.bnr.ca

In article &lt;3298@deadmin.ucsd.edu&gt;,
Booker C. Bense &lt;bense@heart3.ucsd.edu&gt; wrote:
&gt;- I need to write a simple database merge program using perl 
&gt;databases. I used the gnu gdbm libraries so I should be able 
&gt;to open more than one dbm file. If anyone has done this I'd 
&gt;appreciate some examples. 
&gt;
&gt;- Thanks 
&gt;
&gt;- 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)' &amp;&amp; eval 'exec /bnr/bootleg/bin/perl -S $0 ${1+"$@"}'
&amp; eval 'exec /bnr/bootleg/bin/perl -S $0 $argv:q'
if $running_under_some_other_shell;

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

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

require 'newgetopt.pl';

sub usage {
    print STDERR &lt;&lt;USAGE;

Usage: $script [-h] [-v] &lt;dbmoutfile&gt; &lt;dbminfiles&gt;

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

USAGE
}

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

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

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

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

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

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

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



</pre></body></html>