
mhx
Enthusiast
Jul 24, 2001, 10:36 PM
Post #2 of 4
(1092 views)
|
It is 3, at least with my HP-UX build of Perl 5.6.0. I'm not sure if there's an easier way to get the value of the reference counter, but mine isn't too hard anyway. (Took me only some minutes.) If you have a look at the perlguts manpage, there's a section Reference Counts and Mortality. There's also an internal routine to retrieve the reference counter value of an SV called SvREFCNT. With this knowledge, one can easily write a small XSUB with the following code:
MODULE = RefCount PACKAGE = RefCount int GetRefCount( sv ) SV *sv CODE: RETVAL = SvREFCNT( sv ); OUTPUT: RETVAL You can then use this XSUB from some Perl code like this:
#!/bin/perl -w use RefCount; $a = 123; $b = \$a; $c = $b; printf "RefCount = %d\n", RefCount::GetRefCount( $a ); And in this case, it will print RefCount = 3. There are also some interesting resources besides the perlguts manpage on the web. There is for example an article called Perl Guts Illustrated that graphically illustrates Perl's internal data types. Also, there's interesting reply by Nathan Torkington concerning circular references and the related problems. Hope this helps. -- Marcus
s$$ab21b8d15c3d97bd6317286d$;$"=547269736;split'i',join$,,map{chr(($*+= ($">>=1)&1?-hex:hex)+0140)}/./g;$"=chr$";s;.;\u$&;for@_[0,2];print"@_,"
|