and this script reads the data back out:#!/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) }; }
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. : )#!/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"; } }
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |