Just wanted to report back on my results, which were phenomenal! This script writes the MySQL database to the DBM file:
#!/usr/bin/perl -w use strict; use Mojo::DB; use DBM::Deep; $| = 1; my $dbh = get_dbh(); die "No filename argument provided" unless @ARGV; my $file = shift @ARGV; unlink $file; # This is the magic. :-) my $db = DBM::Deep->new( $file ); tie my %IDS, 'DBM::Deep', $file or die "$!"; my @keys = qw(employee_id firstname lastname title dept salary date_hi +red); my $keys = join(', ', @keys); my $query = "select $keys from employee_data"; my @values = @{$dbh->selectall_arrayref($query)}; for my $v (@values){ my @vals = @$v; # one ID per array for (@vals){ $_ = '-' unless $_; } $db->{$vals[0]} = { (map { $keys[$_] => $vals[$_]; } 0 .. $#keys) }; }
and this script reads the data back out:
#!/usr/bin/perl -w use strict; use DBM::Deep; $| = 1; die "No filename argument provided" unless @ARGV; my $file = shift @ARGV; tie my %IDS, 'DBM::Deep', $file or die "$!"; while (my($k, $v) = each %IDS){ print "\n$k :\n"; while (my ($k, $v) = each %{$v}){ print "$k => $v\n"; } }
It really works like a dream, thank you so much. The nice thing, too, is that I almost understand how it works! I'm even going to leave your comment about "this is the magic" in there to remind me. : )


Any technology sufficiently advanced is indistinguishable from a Perl script.

In reply to Re^2: Weirdness when reading from DBM file by mojodaddy
in thread Weirdness when reading from DBM file by mojodaddy

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.