in reply to Reference Count of a Non-Scalar
A little Inline::C could do the trick. We could check if the passed in SV is a reference, if so, dereference it and get the SvREFCNT of that. The only issue is to remember that by passing it as \@array we up the reference count.
#!/usr/local/bin/perl -w use Inline C; use strict; my( @x, $z, $r ); @x = qw( a b c d e f g ); $z = \@x; $r = ref_count( \@x ); print "Ref count is $r - expect 3 - initial, ref, and pass ref\n"; $r = ref_count( $z ); print "Ref count is $r - expect 2 - initial, and ref\n"; __END__ __C__ #include <stdio.h> U32 ref_count ( SV * val ) { SV *y; y = SvROK(val) ? SvRV( val ) : val; return SvREFCNT( y ); }
-derby
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Reference Count of a Non-Scalar
by Anonymous Monk on May 25, 2005 at 16:27 UTC |