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.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re^3: can't thaw a hash: Magic number error. by BrowserUk
in thread can't thaw a hash: Magic number error. by balt

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.