Problem when using defrost in a serialized data structure in perl

I use the perl DB_File module to save the hash variable to a file.

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

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

But when I tried to get the values, I got an error. The first time I run the recovery code, it works. The next time he fails.

I used this method:

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

Error message

The saved binary image v25.47 is more recent than me (v2.7) in .. /../lib/Storable.pm (auto-extension in .. /../lib/auto/Storable/thaw.al) line 366, in line retrieve.pl 15 on the page .. /../lib/Storable.pm(auto reset in .. /../lib/auto/Storable/logcroak.al) line 74 Storable :: logcroak (''), called at .. /../lib/Storable.pm(autocompletion in .. /../lib/auto/Storable/thaw.al) line 367 Storable :: thaw ('2/8'), called on the line retrieve .pl 15

+4
source share
2 answers

Look at the error:

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

The value you are trying to thaw is the scalar result of the hash.

I assume $HASH{$key} in

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

contains a hash (may be from frozen objects).

Try to add

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

before trying to thaw the value, see its contents.

0
source
 Storable::thaw($HASH{$key}; 

You forgot to close ()

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

And do you need you to thaw all the keys? I think that you have few fields, and not all of them should be saved.

0
source

All Articles