gregorovius has asked for the wisdom of the Perl Monks concerning the following question:

Dear fellow Monks,

I've ran into a problem with the Storable module, which looks like a bug. Whenever I do a "freeze" after a failed "thaw", Storable will balk with a "bad hash" error coming from within it.

Try the following code, which will work, and then remove the commented out bad thaw and see if it fails on your setting. I run this with the latest Storable (1.011) and Perl 5.6:

#!/usr/bin/perl -w use strict; use Storable qw(freeze thaw); my $thaw_me = 'asdasdasdasd'; #eval { # my $thawed = thaw $thaw_me; #}; #if($@) { # warn "there was a THAWING error\n"; #} my %to_be_frozen = (foo => 'bar'); my $frozen; eval { $frozen = freeze \%to_be_frozen; }; if($@) { die "error while freezing: $@" } print "it froze it\n";

Thanks in advance for any help on fixing this.

Brother Greg

Replies are listed 'Best First'.
(jeffa) Re: Storable bug?
by jeffa (Bishop) on Jun 08, 2001 at 17:37 UTC
    Well, maybe somebody answered your question in the chatterbox, but just in case - the problem is you are trying to 'thaw' something that hasn't been 'frozen', try this instead:
    use strict; use Storable qw(freeze thaw); my %to_be_frozen = (foo => 'bar'); my (%thawed,$frozen); eval { $frozen = freeze \%to_be_frozen; }; if($@) { die "error while freezing: $@" } print "it froze it\n"; eval { %thawed = %{ thaw $frozen }; }; if($@) { warn "there was a THAWING error\n" }
    UPDATE:
    Ok, now i understand what you mean - i added this line:
    eval { my $foo = thaw 'asdasdasdasd'; }; if($@) { warn "there was a THAWING error\n" }
    just before the first eval in my code above and received this output:
    $ ./foo.pl there was a THAWING error error while freezing: Bad hash at blib/lib/Storable.pm (autosplit into + blib/lib/auto/Storable/_freeze.al) line 261, at ./foo.pl line 19
    If this is indeed a bug in Storable, then I would send word to the author . . .

    Jeff

    R-R-R--R-R-R--R-R-R--R-R-R--R-R-R--
    L-L--L-L--L-L--L-L--L-L--L-L--L-L--
    
Re: Storable bug?
by gregorovius (Friar) on Jun 08, 2001 at 18:57 UTC
    Hey, I already knew that!

    The bad thaw is there on purpose, to show that after such failure Storable will stop being able to freeze.

    It appears to be that something goes wrong in the internal state of Storable when you feed a bad value to 'thaw', that prevents it from working again.

    I've tried unloading and reloading after the bad thaw by doing:

    delete $INC{'Storable.pm'}; require Storable;
    But that only replaces the subroutines and doesn't clear the internal state, which is my guess from the barrage of warnings this gives when run under 'use strict'.
      The warnings come from the fact that you overwrite a sub (from the old Storable) with a new sub (from the required Storable) with the same name. The internal state will be reset, but thats ok therefore no warning.