I don't understand why your code displays the strange results it does. Here are some observations.

If I change the last loop to read:

while(1){ shmread($key,$message,0,99); ++$t; my $t_copy = $t; my $message_copy = $message; print "$t_copy - $message_copy is ", $t_copy - $message_copy, +"\n"; sleep 1; }

it all works out.

Adding use Devel::Peek and Dump [$t, $message, $result]; to the original loop shows some other interesting results:

SV = IV(0x1a65bf8) at 0x1a65c08 REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x1a65cb0 SV = PVAV(0x1a54f50) at 0x1a65cb0 REFCNT = 1 FLAGS = () ARRAY = 0x19b75a0 FILL = 2 MAX = 2 ARYLEN = 0x0 FLAGS = (REAL) Elt No. 0 SV = PVNV(0x1a10e10) at 0x1a65d58 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 8 NV = 0 PV = 0 Elt No. 1 SV = PVNV(0x1a5eda0) at 0x19a6a60 REFCNT = 1 FLAGS = (POK,pIOK,pNOK,pPOK) IV = 1 NV = 1 PV = 0x1a2c2b0 "2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\ +0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0 +\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\ +0\0\0\0\0\0"\0 CUR = 99 LEN = 104 Elt No. 2 SV = PVNV(0x1a5edc0) at 0x1a65770 REFCNT = 1 FLAGS = (NOK,POK,pNOK,pPOK) IV = 0 NV = 6 PV = 0x1a37f80 "6"\0 CUR = 1 LEN = 16 8 - 2 is 7

So, lots of trailing \0's in $message. Not sure how that leads to the disconnect between IV/NV and PV though.

Update: removing the \0's seems to fix it too:

$message =~ s/\0+//g;

In reply to Re: Is this a bug in perl or a bug in me? by moritz
in thread Is this a bug in perl or a bug in me? by Wheely

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.