Okay my problem is when trying to use a dbm file from my system on another, which may be a completely different operating system, the file will not work because of the different version libraries installed or whatnot, so I came up with the 2 scripts below.
#!/usr/bin/perl -w use strict; use DB_File; die "usage: dview <file.db> <outputfile>\n" unless (@ARGV == 2); my($db_file, $out_file) = @ARGV; die "Error: $!\n" unless -e $db_file; die "Output file exists\n" if -e $out_file; open OUT_FILE, ">$out_file" or die "Couldn't open $out_file: $!\n"; dbmopen my %DB, "$db_file", 0666 or die "Couldn't open DB: $!\n"; for (sort keys %DB) { print OUT_FILE "key: \"$_\" = \"$DB{$_}\" END\n"; } dbmclose %DB or warn "Couldn't close $db_file: $!\n"; close OUT_FILE or warn "Couldn't close $out_file: $!\n";
That one would dump the contents of the dbm file's hash values into a plain text file and with that plain text file I would create another dbm file with this other script
#!/usr/bin/perl -w use strict; use DB_File; die "usage: dbcreate-dump <file> <out.db>\n" unless (@ARGV == 2); my($in_file, $out_db) = @ARGV; die "Error: $!\n" unless -e $in_file; die "Output DB exists\n" if -e $out_db; local $/; open IN_FILE, "< $in_file" or die "Couldn't open $in_file: $!\n"; my $file_contents = <IN_FILE>; close IN_FILE or warn "Couldn't close $in_file: $!\n"; dbmopen my %DB, "$out_db", 0666 or die "Couldn't open DB: $!\n"; while($file_contents =~ /key: \"(.*)\" = \"(.*)\" END/g) { $DB{$1} = $2; } dbmclose %DB or warn "Couldn't close $out_db: $!\n";
But all that seems a little over complicated I thought when I remembered Data::Dumper and maybe using it dump the values into a plain text file and eval that or something. But the something is where I'm stuck I have no idea how to achive this using Data::Dumper, so far I've tried
#!/usr/bin/perl -w use strict; use DB_File; use Data::Dumper; dbmopen my %NEWS_DB, "news.db", 0666 or die "Couldn't open news.db: $! +\n"; my $news_db = \%NEWS_DB; my $data = Dumper $news_db; dbmopen my %NEW_DB, "new.db", 0666 or die "Couldn't open new.db: $!\n" +; %NEW_DB = eval(Dumper($data));
Of course that doesn't work and the Data::Dumper man page just confuses me even more :( so any help would be greatly appreciated.

In reply to 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.