in reply to Re^2: can't thaw a hash: Magic number error.
in thread can't thaw a hash: Magic number error.
I suspect the problem is that, in either case, the length of the value returned from shared memory is a full 1024 bytes despite that the length of the original frozen hash is less that 100 bytes. It is probably those extra bytes -- that might be space or null padded; or just random garbage -- that are upsetting the thaw process.
Without having tested it -- IPC::SysV doesn't work on my system -- what I think you should be doing is something like this:
my $serialized = pack 'L/a', freeze \%somehash; $shm_somehash->write( $serialized, 0, 1024); ... my $unpacked = unpack "L/a", $shm_somehash->read( 0, 1024); my %hash = %{ thaw $unpacked };
The idea being that the 'L/a' template packs the string with a prefix of the number of characters that are packed. Thus when you unpack it, despite that you read back 1024 bytes from the shared memory, only the same number of bytes as where in the original freeze'd string will be returned, devoid of any packing, and (hopefully) when you pass that to thaw, it should be exactly what it is expecting.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: can't thaw a hash: Magic number error.
by balt (Novice) on Nov 03, 2015 at 23:43 UTC |