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

Hello, I'm trying to use Storable freeze and thaw to serialize/deserialize an array so I can fetch and store it using ShareLite. The problem:
use Storable qw( freeze thaw); my @regarray; my $share = new IPC::ShareLite(-key=>1971, -create=>"yes", -destroy=>"no") or die $!; @regarray = thaw($share->fetch);
Won't compile. Gives error "Storable binary image v57.111 more recent than I am (v2.6) at .." Any ideas?

Replies are listed 'Best First'.
Re: Storable image problem
by tachyon (Chancellor) on Feb 22, 2004 at 13:29 UTC

    That snippet will never work. You need to use IPC::ShareLite, but more importantly: how do you expect to fetch something from shared memory if you have not stored anything there in the first place?

    I would first check that storable is working by freeze/thaw a var and make sure you get it back. Then store the serialised obect into shared memory, get it back, deserialize and check, then try to do it all in one line if you really want to. Untested: Works fine on RH 7.3 with Perl 5.6.2 and module versions shown.

    #!/usr/bin/perl -w use strict; use Storable qw( freeze thaw); use IPC::ShareLite; printf "Storable %s\nIPC::ShareLite %s\n", $Storable::VERSION, $IPC::S +hareLite::VERSION; my $ary = [ qw( Use shared memory ) ]; my $frozen = freeze( $ary ); my $thaw = thaw( $frozen ); print "Freeze/thaw ok\n" if "@$ary" eq "@$thaw"; my $share = new IPC::ShareLite(-key=>1971, -create=>"yes", -destroy=>"no") or die $!; $share->store( $frozen ); my $shm_frozen = $share->fetch; my $shm_thaw = thaw( $shm_frozen ); print "Share mem freeze/thaw ok\n@$shm_thaw!\n" if "@$ary" eq "@$shm_t +haw"; [root@devel3 root]# ./shm_test.pl Storable 1.014 IPC::ShareLite 0.09 Freeze/thaw ok Share mem freeze/thaw ok Use shared memory! [root@devel3 root]#

    cheers

    tachyon

Re: Storable image problem
by Corion (Patriarch) on Feb 22, 2004 at 13:19 UTC

    I don't know what IPC::ShareLite implements, so here are the generic questions:

    Are you sharing the data between different machines? Different byte order?

    Are you using different versions of Perl and/or Storable.pm in your two scripts?

    Is IPC::ShareLite prepending some data to the result of $share->fetch?

    Update: After looking at the documentation, I don't see any bad warnings, so I guess that somewhere your memory gets corrupted, as the Storable version number seems a bit weird.

Re: Storable image problem
by Anonymous Monk on Feb 22, 2004 at 15:41 UTC
    Try
    perl -MStorable -e 1
    and report what you get. It sounds like you've got a corrupted install of Storable (picking up the wrong PATH or the wrong something from the wrong PATH)
Re: Storable image problem
by Roger (Parson) on Feb 23, 2004 at 00:46 UTC
    I had similar problem when I played with storable in my Win32::MMF module, which is shared memory under Windows, also uses the Storable module. I found that this problem happens usually when you are trying to:

    - read data unlocked, while another process trying to write data to shared memory at the same time and corrupted the shared memory. This happens a lot with arrays and hashes.

    The work around is to lock the shared memory while reading and writing.