On Mon, Jul 14, 2008 at 08:32:52PM +0100, Paul LeoNerd Evans wrote:

>   sub is_1ref
>   {
>      my ( undef, $name ) = @_;
>      my $count = refcount($_[0]);
>      ...
>   }
> 
> The $object in the first code creates a second reference, so you have to
> subtract 1, whereas the @_ array seems special and doesn't have that
> side-effect.

Until you take a reference to it, or various other things (I cant' remember the
canonical list, but push is in it, whereas shift doesn't seem to be (at least
a simple shift)):

$ perl -MDevel::Peek -e 'sub f {Dump $_[0]; warn [EMAIL PROTECTED]; Dump $_[0]; 
} f(\$v)'
SV = RV(0x817e18) at 0x800168
  REFCNT = 1
  FLAGS = (ROK)
  RV = 0x800f18
  SV = NULL(0x0) at 0x800f18
    REFCNT = 2
    FLAGS = ()
ARRAY(0x800f00) at -e line 1.
SV = RV(0x817e18) at 0x800168
  REFCNT = 2
  FLAGS = (ROK)
  RV = 0x800f18
  SV = NULL(0x0) at 0x800f18
    REFCNT = 2
    FLAGS = ()

It would be dangerous to rely on this reference counting behaviour remaining
the same.

Nicholas Clark

Reply via email to