#!/usr/bin/perl

# ndbm2db.pl - Perl script to convert old ndbm to db format
# assume the goal is to have the data on a machine without NDBM and 
# DB is the default and AnyDBM_File will be used on the new system software
# only catch is ndbm is no longer part of the rpm for perl redhat
# so, you need to do this before upgrading or install an old version

use POSIX;
use NDBM_File;
use DB_File;
while ($ARGV = shift) {
    if ($ARGV =~ /^(.*)\.db$/) {
	my $old_filename = $1;
	my $new_filename = "$1.AnyDBM";
	tie %newhash, DB_File, $new_filename, O_CREAT|O_RDWR;
	tie %oldhash, NDBM_File, $old_filename, 1, 0;
	%newhash = %oldhash;
	untie($newhash);
	untie($oldhash);
	print "Converted $ARGV (NDBM) -> $new_filename (DB)\n";
    } else {
	print "Ignored $ARGV wrong extension for NDBM file\n";
    }
}
