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...


In reply to Re: runtime problem; elusive error by almut
in thread runtime problem; elusive error by perl-diddler

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.