in reply to Re: Number of times I've used goto in Perl
in thread Number of times I've used goto in Perl
Well the people mentioning AUTOLOAD are actually talking about this version of goto. For example this post explicitly mentions goto &{ $AUTOLOAD };.
The interest of goto isn't only about the fact that it transmits the current value of @_ to the called sub. Actually this is already the case when you do this:
this is documented in perlsubsub exportFunctionName { &_internalImplementation; }
If a subroutine is called using the & form, the argument list is optional, and if omitted, no @_ array is set up for the subroutine: the @_ array at the time of the call is visible to subroutine instead. This is an efficiency mechanism that new users may wish to avoid.Actually I'm pretty sure there was a post about goto being slower than a simple function call (because it has to exit the the local changes) but I couldn't find it.
So the main interest of goto lies in the fact that it doesn't add a function to the calling stack but instead replaces the current one. This means that with this code:
The B function will never see &A in the calling stack, but only &_A. This can be used for debbuging, when you want to call a wrapper function (to print "About to enter &function", or check the input). I remember this question where this was precisely what the OP asked for.sub A { goto &_A; } sub _A { B(); }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Number of times I've used goto in Perl
by HugoNo1 (Novice) on Sep 26, 2018 at 18:34 UTC | |
by Eily (Monsignor) on Sep 27, 2018 at 00:15 UTC | |
by HugoNo1 (Novice) on Oct 03, 2018 at 09:54 UTC | |
by Eily (Monsignor) on Oct 03, 2018 at 10:02 UTC | |
by Anonymous Monk on Sep 26, 2018 at 20:12 UTC |
In Section
Past Polls