Motional Monks,
For depressing-to-explain reasons, we're using an old DBM file (data_dbm_file) as a backup to a small sql database (data_db) of name/value pairs. Each time data_db is updated, the following sub routine is run:
tie %data_hash, "SDBM_File", "data_dbm_file", O_RDWR|O_CREAT, 0666
+ || die "Cannot open file 'data_dbm_file': $!\n";
%data_hash = ();
$sqlSelect = "SELECT field1, field2 FROM $data_db";
$sth = $dbh->prepare($sqlSelect) || die "Cannot prepare: " . $dbh-
+>errstr();
$sth->execute() or die "Cannot execute: " . $sth->errstr();
while (@data = $sth->fetchrow_array()) {
my $data_to_store = crypt($data[1], $private_key);
$data_hash{$data[0]} = $data_to_store;
}
untie %data_hash;
$sth->finish();
And this is re-run every time there's a change to the data_db database. So, essentially, the DBM file gets completely re-written every time there's any change to the data_db database.
It seems to work just fine - the DBM file is checked on occasion and always mirrors the sql database.
BUT - there's always a but - if I ftp a copy of the data_dbm_file from the server onto my (Windows) PC, and open it in Notepad, among the long list of data I find this sort of thing:
bogA4dxaWfeMo:Namen_
bogA4dxaWfeMo:Namen_
bogA4dxaWfeMo:Namen
bogA4dxaWfeMo:Name
bogA4dxaWfeMo:Namen_0
bogA4dxaWfeMo:Namen_0
bogA4dxaWfeMo:Namen
bogA4dxaYbogA4dxaWfeMo:Name
bogA4dxaWfeMo:Name
bogA4dxaWfeMo:Namen
acbogA4dxaWfeMo:Namen
abogA4dxaWfeMo:Namen
Multiple entires with slight variations of old name/value pairs that were thought to be deleted long ago. There can be dozens of them for a single name. But they don't appear in a listing of the contents of the DBM file if we do:
tie %h, "DB_File", "data", O_RDWR|O_CREAT, 0666, $DB_HASH or die "Cann
+ot open file 'data': $!\n";
print "Content-type:text/html\n\n";
foreach my $key (sort keys %h) {
print "<br>$key -> $h{$key}\n";
}
This outputs just the expected name/value pairs.
What is all this extra cruft? Is this due to something about our re-writing sub-routine? Or a typical result in a DBM file? Or something else?
Thanks.
Time flies like an arrow. Fruit flies like a banana.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.