3 # $Id: shrinkdbm.pl,v 1.1.2.1.2.3 2005-01-07 14:02:27 rurban Exp $
6 # Steve Wainstead, July 2000
7 # this script is public domain and has no warranty at all.
13 use vars ('$opt_o', '$opt_i');
14 my (%old_db, %new_db);
16 # $opt_i == input file
17 # $opt_o == output file
20 # less confusing names
21 my $input_db_file = $opt_i;
22 my $output_db_file = $opt_o;
25 die <<"USAGE" unless ($input_db_file and $output_db_file);
26 Usage: $0 -i <infile> -o <outfile>
27 where: infile is a GDBM file and,
28 outfile is the name of the new file to write to.
30 The idea is to copy the old DB file to a new one and thereby
36 tie (%old_db, "GDBM_File", $input_db_file, O_RDWR, 0666)
37 or die "Can't tie $input_db_file: $!\n";
39 print "There are ", scalar(keys %old_db), " keys in $input_db_file\n";
41 # open new file, deleting it first if it's already there
42 if (-e $output_db_file) { unlink $opt_o; }
43 tie (%new_db, "GDBM_File", $output_db_file, O_RDWR|O_CREAT, 0666)
44 or die "Can't tie $input_db_file: $!\n";
47 while (my($key, $value) = each(%old_db)) {
48 $new_db{$key} = $value;
51 print "There are now ", scalar(keys %old_db), " keys in $input_db_file\n";
52 print "There are ", scalar(keys %new_db), " keys in $output_db_file\n";