John M. Dlugosz has asked for the wisdom of the Perl Monks concerning the following question:

Speaking of the & syntax for replacing a stack frame (it came up in another posting today), can you do that with an indirect call, that is, something like
sub callit { $p->(@_); }
without having to re-push everything?

Replies are listed 'Best First'.
Re: stack-frame-substituting subs indirectly?
by BrowserUk (Patriarch) on Nov 05, 2002 at 03:12 UTC

    You could use the magical form of goto.

    From perlsyn

    The goto-&NAME form is highly magical, and substitutes a call to the n +amed subroutine for the currently running subroutine. This is used by + AUTOLOAD() subroutines that wish to load another subroutine and then + pretend that the other subroutine had been called in the first place + (except that any modifications to @_ in the current subroutine are p +ropagated to the other subroutine.) After the goto, not even caller() + will be able to tell that this routine was called first.

    So this should work (I think).

    sub callit { goto &$p; }

    Nah! Your thinking of Simon Templar, originally played by Roger Moore and later by Ian Ogilvy
      Wow, I didn't know that Perl had a goto funtion. ... Something to abuse. :)

      When I've learned how to use it correctly. :(

        see Would you use 'goto' here? for one of the best discussions related to goto on this site, before you cause too much trouble ;)

        ~Particle *accelerates*