Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] Converting Berkeley DB to GNU dbm



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Tue, Sep 03, 2002 at 03:48:04PM +0800, Shimpei Yamashita wrote:
> 
> If you can't find a customized tool, try hacking one together using the
> DB_File and GDBM_File modules in perl. Tie the old password file to a
> DB_File hash, tie the new password to a GDBM_File hash, do a
> foreach(keys())
> through the old file and populate the new file. Should work--in theory,
> assuming that things like password encoding format haven't changed.

Found this example in the Perl Bookshelf:


#!/usr/bin/perl -w
# db2gdbm: converts DB to GDBM

use strict;

use DB_File;
use GDBM_File;

unless (@example.com == 2) {
    die "usage: db2gdbm infile outfile\n";
}

my ($infile, $outfile) = @example.com;                    
my (%db_in, %db_out);                              

# open the files
tie(%db_in, 'DB_File', $infile)
    or die "Can't tie $infile: $!";
tie(%db_out, 'GDBM_File', $outfile, GDBM_WRCREAT, 0666)
    or die "Can't tie $outfile: $!";

# copy (don't use %db_out = %db_in because it's slow on big databases)
while (my($k, $v) = each %db_in) {
    $db_out{$k} = $v;
}

# these unties happen automatically at program exit
untie %db_in;
untie %db_out;



Am trying it now. Hope it works.


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE9dGzIt1KjqyZ+DQ4RArYfAJ4udO75gavldFBwSd8HZ355FF16IACfQ8N+
OvTsWgumTUYEqc7x8NqSK2E=
=151K
-----END PGP SIGNATURE-----


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links