in reply to Is this a bug in perl or a bug in me?
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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Is this a bug in perl or a bug in me?
by Corion (Patriarch) on Sep 05, 2011 at 19:15 UTC | |
by Wheely (Acolyte) on Sep 05, 2011 at 19:37 UTC | |
by Corion (Patriarch) on Sep 06, 2011 at 11:37 UTC | |
by Anonymous Monk on Sep 05, 2011 at 21:03 UTC | |
by JavaFan (Canon) on Sep 05, 2011 at 23:22 UTC |