in reply to Re: Dumping undef as a constant produces strange REFCNT
in thread Dumping undef as a constant produces strange REFCNT

It does indeed seem to be counting down as more use/require etc statements are added or eval'd. In fact, any successful eval will also lower the count. Something as simple as eval('#') lowers the count by one.

The below gives me the highest output count I can get of 2147483604. My guess would be that 2147483647, max val for signed long, is the starting point.

I'm also curious whether this is some real count value or some artifact of Devel::Peek

require Devel::Peek; Devel::Peek::Dump(undef); # SV = NULL(0x0) at 0x993788 # REFCNT = 2147483604 # FLAGS = (READONLY)

Replies are listed 'Best First'.
Re^3: Dumping undef as a constant produces strange REFCNT
by ikegami (Patriarch) on Aug 24, 2011 at 23:50 UTC

    I'm also curious whether this is some real count value or some artifact of Devel::Peek

    It's the real value of the REFCNT field, but it does not indicate the number of references to that scalar.

    My guess would be that 2147483647, max val for signed long, is the starting point.

    Yes, or more precisely, the midpoint of 32-bit unsigned ints (even on a 64-bit build).

    The max value wouldn't be good because it's possible to increase it.

    $ perl -E' sub show { say &Internals::SvREFCNT( \undef ); } show(); push @a, \undef for 1..5; show(); ' 2147483623 2147483628

    Of course, it's also possible to reduce it.

    $ perl -E' sub show { say &Internals::SvREFCNT( \undef ); } show(); { my @a; $#a = 5; } show(); ' 2147483623 2147483617