Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: DBM files between systems

by Speedy (Monk)
on Feb 23, 2002 at 20:17 UTC ( [id://147097]=note: print w/replies, xml ) Need Help??


in reply to DBM files between systems

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://147097]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-05-21 01:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found