[英]GDBM_File interoperability issue transitioning from older 32-bit Perl to 64-bit Perl
I have some GDBM files created using an old 32-bit (i686) version of Perl (5.8.6) that I want to use with an x86_64 Perl 5.28.0, but it doesn't work.我有一些使用旧的 32 位 (i686) 版本的 Perl (5.8.6) 创建的 GDBM 文件,我想与 x86_64 Perl 5.28.0 一起使用,但它不起作用。 Here's my test code:
这是我的测试代码:
use strict;
use warnings;
use GDBM_File;
my $dbmfile = "/path/to/gdbm_test_file";
my %DBM;
eval {
my $ok = tie(%DBM, 'GDBM_File', $dbmfile, &GDBM_WRCREAT, 0664);
die "Error: Bad status!\n" unless $ok;
};
die "Error: Could not open $dbmfile.\n" if $@;
foreach my $key (sort(keys(%DBM))) {
print "$key :: $DBM{$key}\n";
}
untie %DBM;
If I run this code with the older i686 Perl and $dbmfile
pointing to a GDBM file recently created by the same i686 Perl, it correctly reads the GDBM file and prints out its contents.如果我使用旧的 i686 Perl 和
$dbmfile
运行此代码,该代码指向最近由同一个 i686 Perl 创建的 GDBM 文件,它会正确读取 GDBM 文件并打印出其内容。
If I run this code with x86_64 Perl 5.28.0, however, it just silently fails .但是,如果我使用 x86_64 Perl 5.28.0 运行此代码,它只是默默地失败了。 No error.
没有错误。 No output at all.
根本没有输出。
If I run this code with x86_64 Perl 5.10.1, the eval
catches the "Bad status" error, and I get Error: Could not open /path/to/gdbm_test_file.
如果我使用 x86_64 Perl 5.10.1 运行此代码,则
eval
捕获“错误状态”错误,并且出现Error: Could not open /path/to/gdbm_test_file.
If I create a new GDBM file using x86_64 Perl 5.28.0 and try to read it with the old i686 Perl, i686 Perl dies with read error
on the foreach
line.如果我使用 x86_64 Perl 5.28.0 创建一个新的GDBM 文件并尝试使用旧的 i686 Perl 读取它,i686 Perl 会因
foreach
行上的read error
死亡。
Platform: CentOS 6.8平台:CentOS 6.8
gdbm.i686 and gdbm.x86_64 packages are both installed and both are the same version: 1.8.0-39 gdbm.i686 和 gdbm.x86_64 包都安装了并且都是相同的版本:1.8.0-39
Any suggestions?有什么建议? Is this not possible?
这不可能吗?
Given your comment about how 32-bit gdbm databases and 64-bit gdbm databases aren't compatible, I'd use a 32-bit version of the gdbm_dump
utility to dump the database to a flat file, and then feed it to a 64-bit version of gdbm_load
to re-create the database so it can be read by the 64-bit perl gdbm library.鉴于您对 32 位 gdbm 数据库和 64 位 gdbm 数据库不兼容的评论,我将使用 32 位版本的
gdbm_dump
实用程序将数据库转储到平面文件,然后将其提供给 64 -bit 版本的gdbm_load
重新创建数据库,以便 64 位 perl gdbm 库可以读取它。
You might have to build these from source to get the appropriate versions depending on what packages CentOS provides - I'm not familiar with it.根据 CentOS 提供的软件包,您可能必须从源代码构建它们以获得适当的版本 - 我不熟悉它。
Alternatively, write a quick tool using the 32-bit version of perl to read the 32-bit gdbm database and convert it to a different dbm that doesn't suffer from the same problem so both 32-bit and 64-bit programs can use the same file.或者,使用 32 位版本的 perl 编写一个快速工具来读取 32 位 gdbm 数据库并将其转换为不会遇到相同问题的不同 dbm,因此 32 位和 64 位程序都可以使用同一个文件。
Psuedocode:伪代码:
tie my %gdbm, 'GDBM_File', 'olddb.gdbm', read-only options;
tie my %other, 'Other_DBM', 'newdb.whatever', write/create options;
while (my ($key, $value) = each %gdbm) {
$other{$key} = $value;
}
untie %gdbm;
untie %other;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.