While I was trying to learn something about perl internals and playing with Devel::Peek, I noticed the following behavior that I don't understand. The following simple script:
# devel.pl use Devel::Peek; my $a = undef; Dump $a; my $b = \$a; Dump $a; # note the reference count for $a
produces the correct reference count for $a when running "perl -d devel.pl", the output is as follows:
c:>perl -d devel.pl Loading DB routines from perl5db.pl version 1.23 Editor support available. Enter h or `h h' for help, or `perldoc perldebug' for more help. main::(devel.pl:3): my $a = undef; DB<1> n main::(devel.pl:4): Dump $a; DB<1> n SV = NULL(0x0) at 0x1829ce0 REFCNT = 1 FLAGS = (PADBUSY,PADMY) main::(devel.pl:5): my $b = \$a; DB<1> n main::(devel.pl:6): Dump $a; DB<1> n SV = NULL(0x0) at 0x1829ce0 REFCNT = 2 ###<----- correct count FLAGS = (PADBUSY,PADMY)
But if I do an interactive session using "perl -de 1", it produces the wrong count for $a:
c:>perl -de 1 Loading DB routines from perl5db.pl version 1.23 Editor support available. Enter h or `h h' for help, or `perldoc perldebug' for more help. main::(-e:1): 1 DB<1> use Devel::Peek; DB<2> my $a = undef; DB<3> Dump $a; SV = NULL(0x0) at 0x1aeccfc REFCNT = 1 FLAGS = () DB<4> my $b = \$a; DB<5> Dump $a; SV = NULL(0x0) at 0x1aeccfc REFCNT = 1 ###<----- wrong reference count FLAGS = ()
However, if I do not use "my" in the above interactive session, all is well:
c:>perl -de 1 Loading DB routines from perl5db.pl version 1.23 Editor support available. Enter h or `h h' for help, or `perldoc perldebug' for more help. main::(-e:1): 1 DB<1> use Devel::Peek; DB<2> $a = undef; DB<3> Dump $a; SV = NULL(0x0) at 0x1aecc18 REFCNT = 1 FLAGS = () DB<4> $b = \$a; DB<5> Dump $a; SV = NULL(0x0) at 0x1aecc18 REFCNT = 2 ###<--------correct here FLAGS = ()
What's going on here?

In reply to Strange behavior of "my" in "perl -d" and "perl -de" by johnnywang

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.