Hong Wang wrote:

> We like to convert db files between liux platform and solaris platform. for 
> example, on solaris, we read the db file and print it to a text file. Then 
> convert the text file to db file on Linux platform.
> 
> Read db file and print it to a text file, it is ok. But how to convert the 
> text file to a db file?
> 
> The script to read the db file and print it to a text file:
> 
> 
> #!/usr/bin/perl
> 
> use GDBM_File;
> 
> $filename="hwang_userdb";
> 
> die "no file: $@" unless $ARGV[0];
> 
> dbmopen( %db, $ARGV[0], undef) or die "could not open database file 
> $ARGV[0]: $! $@";
> 
> open(FILE,">$filename") ||die "couldn't open file $filename";
> 
> foreach $key (sort keys(%db))
> {
>   print  FILE "$key=>$db{$key}\n";
> }
> 
> dbmclose %db;
> 
> 
> But how to convert the text file to a db file?

Read the pod in GDBM_File:

=head1 SYNOPSIS

    use GDBM_File;
    tie %hash, 'GDBM_File', $filename, &GDBM_WRCREAT, 0640);

# you might want to test for error on the tie here

    # Use the %hash array.

# Your code goes here

    untie %hash;

open your text file and read line by line splitting on /\s*=>\s*/ and store
in the hash - then untie hash and exit.  I think DB_File might be a better
choice than GDBM_File, but TEHO.

-- 
  ,-/-  __      _  _         $Bill Luebkert    Mailto:[EMAIL PROTECTED]
 (_/   /  )    // //       DBE Collectibles    Mailto:[EMAIL PROTECTED]
  / ) /--<  o // //      Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_</_</_    http://dbecoll.tripod.com/ (Free site for Perl/Lakers)

_______________________________________________
Perl-Unix-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to