in reply to Re: Checking for "return undef"
in thread Checking for "return undef"

Actually, a method can change the object it is called on, by assigning to $_[0]. This came as a surprise to me.

That's because @_ contains aliases to the passed arguments. It can be useful, but it's dangerous :)

Cheers,
Ovid

New address of my CGI Course.

Replies are listed 'Best First'.
Re: Re: Re: Checking for "return undef"
by ysth (Canon) on Apr 21, 2004 at 18:35 UTC
    I know about the aliasing; I just assumed that the object passed was a shallow copy rather than the real McCoy.

      I recall being surprised that $_[0] was a shallow copy and that assigning to $_[0] didn't change (the scalar holding) the object that invoked the method. I recall this being discussed in a node here (a while ago). I recall being surprised to hear the opposite (more recently but still at least weeks, probably months ago).

      So I think there used to be protections (perhaps unintentional) against modifying $_[0] in a method call and a while ago Perl changed in this regard.

      Sorry, I was unable to find hard references in the time allotted. I hope the wild rumors prove of some use anyway.

      - tye