4

I am using perl DB_File module to persist the hash variable into a file.

My hash variable contains key as normal string and value as another hash variable.

I used Storable::freeze(\%value); to serialize the hash value.

But when I tried to retrieve the values, I got an error. For the first time when I run the retrieve code, it works. The next consecutive times, it fails.

I used method like this:

tie(%HASH, "DB_File", "dbfile", O_RDWR, 0444); 
foreach $key (%HASH)
{
    $hashRef = Storable::thaw($HASH{$key};  --> here it fails with the error 
}

Error message

Storable binary image v25.47 more recent than I am (v2.7) at ../../lib/Storable.pm (autosplit into ../../lib/auto/Storable/thaw.al) line 366, at retrieve.pl line 15 at ../../lib/Storable.pm (autosplit into ../../lib/auto/Storable/logcroak.al) line 74 Storable::logcroak('') called at ../../lib/Storable.pm (autosplit into ../../lib/auto/Storable/thaw.al) line 367 Storable::thaw('2/8') called at retrieve.pl line 15

4

2 に答える 2

0

エラーを見てください:

.... Storable::thaw('2/8') called ....

解凍しようとしている値は、ハッシュのスカラー結果です。

$HASH{$key}

$hashRef = Storable::thaw($HASH{$key});

ハッシュが含まれています(凍結されたオブジェクトの場合があります)。

追加してみてください

use Data::Dumper;
print 'content : '.Dumper $HASH{$key};

値を解凍する前に、その内容を確認してください。

于 2013-02-17T08:23:58.447 に答える
0
Storable::thaw($HASH{$key};

() を閉じるのを忘れている

Storable::thaw($HASH{$key});

そして、すべての鍵を解凍する必要があると確信していますか? フィールドはほとんどなく、すべてが保存可能である必要はないと思います。

于 2013-02-21T16:28:32.310 に答える