in reply to Checking for "return undef"

sub load_session { ... return undef; ... } And now consider my code: ... $sid = $cookies->{license_session}->value(); # load session from db my $s = Mapps::Session->new(); $s->load_session($sid); # session is good continue if (defined $s){ $m->call_next; }
return controls what the sub returns, but you aren't using a return value. load_session isn't ever going to change $s. Try:
if (defined $s->load_session($sid)) { $m->call_next; }
(Actually, a method can change the object it is called on, by assigning to $_[0]. This came as a surprise to me.)

Replies are listed 'Best First'.
Re: Re: Checking for "return undef"
by Ovid (Cardinal) on Apr 21, 2004 at 16:33 UTC

    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.

      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