johnnywang has asked for the wisdom of the Perl Monks concerning the following question:
produces the correct reference count for $a when running "perl -d devel.pl", the output is as follows:# devel.pl use Devel::Peek; my $a = undef; Dump $a; my $b = \$a; Dump $a; # note the reference count for $a
But if I do an interactive session using "perl -de 1", it produces the wrong count for $a: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)
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> 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 = ()
What's going on here?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 = ()
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Strange behavior of "my" in "perl -d" and "perl -de"
by tlm (Prior) on Apr 15, 2005 at 22:37 UTC | |
|
Re: Strange behavior of "my" in "perl -d" and "perl -de"
by Fletch (Bishop) on Apr 15, 2005 at 23:40 UTC | |
by johnnywang (Priest) on Apr 16, 2005 at 06:02 UTC | |
by Fletch (Bishop) on Apr 16, 2005 at 13:43 UTC |