in reply to runtime problem; elusive error

It seems the tiedscalar magic is somehow being applied incorrectly, when a 'virgin' readonly scalar is being used in a bitwise OR operation. With 'virgin' I mean that the variable hasn't been accessed before. Once the variable has been accessed/initialised (note the difference in the Devel::Peek dump before and after), things start to work as expected, i.e. the OR operation then seems to default to numeric interpretation. Compare:

use Devel::Peek; use Readonly; Readonly my $C1 => 0x0004; Readonly my $C2 => 0x0008; Dump($C1); # before first evaluation #Dump($C2); my @x = ($C1, $C2); # somehow access variables my $C3 = $C1 | $C2; Dump($C1); # after first evaluation #Dump($C2); print "\nValue of C3 = ", $C3, "\n";

If you comment out the line "my @x = ($C1, $C2);", $C3 will be "<" (i.e. string OR of "8" | "4"), while with the line being active, you'd get 12 (i.e. numeric OR of 8 | 4 ).

Example output without pre-evaluating $C1 and $C2:

SV = PVMG(0x69b788) at 0x65eb00 REFCNT = 1 FLAGS = (PADBUSY,PADMY,GMG,SMG,RMG) IV = 0 NV = 0 PV = 0 MAGIC = 0x6e8ff0 MG_VIRTUAL = &PL_vtbl_packelem MG_TYPE = PERL_MAGIC_tiedscalar(q) MG_FLAGS = 0x02 REFCOUNTED MG_OBJ = 0x63c430 SV = RV(0x676bd8) at 0x63c430 REFCNT = 1 FLAGS = (ROK) RV = 0x6b87d0 SV = PVMG(0x69b750) at 0x6b87d0 REFCNT = 1 FLAGS = (PADBUSY,PADMY,OBJECT,IOK,POK,pIOK,pPOK) IV = 4 NV = 0 PV = 0x7083b0 "4"\0 CUR = 1 LEN = 8 STASH = 0x6b8990 "Readonly::Scalar" SV = PVMG(0x69b788) at 0x65eb00 REFCNT = 1 FLAGS = (PADBUSY,PADMY,GMG,SMG,RMG,pIOK,pPOK) # <--- IV = 4 NV = 0 PV = 0x6b4c50 "4"\0 CUR = 1 LEN = 8 MAGIC = 0x6e8ff0 MG_VIRTUAL = &PL_vtbl_packelem MG_TYPE = PERL_MAGIC_tiedscalar(q) MG_FLAGS = 0x02 REFCOUNTED MG_OBJ = 0x63c430 SV = RV(0x676bd8) at 0x63c430 REFCNT = 1 FLAGS = (ROK) RV = 0x6b87d0 SV = PVMG(0x69b750) at 0x6b87d0 REFCNT = 1 FLAGS = (PADBUSY,PADMY,OBJECT,IOK,POK,pIOK,pPOK) IV = 4 NV = 0 PV = 0x7083b0 "4"\0 CUR = 1 LEN = 8 STASH = 0x6b8990 "Readonly::Scalar" Value of C3 = <

Strange...