in reply to Aliasing and return, how does return work?

Make it an lvalue function:
sub ret :lvalue { $_[0] }
Notice: I didn't put return() in there -- that's a necessity for an lvalue function.
_____________________________________________________
Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a job (NYC-area)
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Replies are listed 'Best First'.
Re^2: Aliasing and return, how does return work?
by bsb (Priest) on Jun 30, 2004 at 04:37 UTC
    I think this could work but I'm not having much joy so far. I'm still on perl version 5.6.1 which could easily be a factor.

    Will an lvalue sub work when called as &ret = 123?

    I ask because I'm trying to do parameter preprocessing for the caller and was doing it with &ret.

      I'm not sure if lvaluable subs work in 5.6.1. This code works for me with Perl 5.8.4:
      sub ret :lvalue { $_[0] } sub foo { &ret++; print "ARGS: <@_>\n"; } my ($x, $y) = (10, 20); foo($x, $y); __END__ ARGS: <11 20>
      Make sure you aren't accidentally shifting the argument you're planning on setting before you set it.
      _____________________________________________________
      Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a job (NYC-area)
      s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;
        Got your results with 5.6.1, must be my sketchy understanding at fault.

        Aha, it was my testing code messing up, reassigning during the middle of the test. Thanks

        update: I may have spoken too soon...