Christiansen & Torkington in the Perl Cookbook, Chapter 14, recipe 3 - "Converting between DBM files", show something similar to your code.

The relevant portion of that code for your problem is:

# 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; }
I think you may be overcomplicating the text-file creation part. Why not just modify the Cookbook code above a bit with something like this snippet:
# open the files tie(%db_in, 'DB_File', $infile) or die "Can't tie $infile: $!"; open TEXT_OUT, ">$outfile" or die "Can't open $outfile: $!"; while (my($key, $value) = each %db_in) { print TEXT_OUT "$key\n$value\n"; }
This way you need not slurp the whole file in (may not be scalable if the original file is large), and after moving the text file to the new system you need only reverse the process, making each odd row the key and the next row the new DBM value of the new file. Even if $value happened to be undef, that state is still preserved.

I only ask for information. -- Charles Dickens David Copperfield

In reply to Re: DBM files between systems by Speedy
in thread DBM files between systems by rendler

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.