Devel::Peek has a function, SvREFCNT, that lets you find out the reference count of a scalar value or variable. Unfortunately, it doesn't seem to have any way of determining the reference count of a non-scalar variable.
The only way I have been able to think of to find the ref count for, say, an array variable would be to parse the output of Devel::Peek's Dump function. This seems to me, however, to be a Really Bad Idea.
Can anyone point me to a way to get the ref count without resorting to this kind of chicanery?
Example Code:
#!/usr/bin/perl -l use Devel::Peek qw( Dump SvREFCNT ); my $a = 1; my $ra = \$a; print SvREFCNT($a); # prints 2 print SvREFCNT($ra); # prints 1 print SvREFCNT($$ra); # prints 2 my @b = (1, 2); my $rb = \@b; Dump($rb);
Output (the information I seek is in blue):
2
1
2
SV = RV(0x8103b88) at 0x80fd5c0
REFCNT = 1
FLAGS = (PADBUSY,PADMY,ROK)
RV = 0x80fd5a8
SV = PVAV(0x80f77bc) at 0x80fd5a8
REFCNT = 2
FLAGS = (PADBUSY,PADMY)
IV = 0
NV = 0
ARRAY = 0x81226e8
FILL = 0
MAX = 3
ARYLEN = 0x0
FLAGS = (REAL)
Elt No. 0
SV = IV(0x80ff80c) at 0x80f62ac
REFCNT = 1
FLAGS = (IOK,pIOK)
IV = 1
bbfu
Seasons don't fear The Reaper.
Nor do the wind, the sun, and the rain.
We can be like they are.
In reply to Reference Count of a Non-Scalar by bbfu
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |