goto &name is not nonsense at all. It's how Autoloader implements its AUTOLOAD() function. The design principle there (skipping over all the important details) is when Autoloader is triggered, AUTOLOAD can generate the requested (but not yet loaded) sub as a coderef, place a symbol for it in the symbol table, and then invoke goto &name as a means of invoking the actual function called without leaving any obvious trace in the call stack of all the Autoload trickery.
This technique is discussed in detail in Simon Cozens' book, Advanced Perl Programming, 2nd Edition (O'Reilly).
A quote from a "Tip" footnote in that book:
goto LABEL and goto &subname are two completely different operations, unfortunately with the same name. The first is generally discouraged, but the second has no such stigma attached to it. It is identical to subname(@_) but with one important difference: the current stack frame is obliterated and replaced with the new subroutine.
In the same book there is also a discussion on using the goto &name construct to create a wrapper for another function. Say you want to add some functionality to an existing function without having to reimplement the function, and you want to do it in a way that doesn't force you to invoke a new function name. You might do something like this:
sub subA { print "You called subA\n"; } { my $oldsub = \&subA; my $wrap = sub { print "You called the wrapper around subA\n"; goto &$oldsub; }; *main::subA = $wrap; } subA(); __END__ You called the wrapper around subA You called subA
Update: After considering the preceding example you might (as I did) suspect that you would find goto &name used in the autodie pragma as well... and as a matter of fact, the Fatal module that does the heavy lifting for autodie doesn't disappoint us; goto &name is an important part of how it works.
Mark Jason Dominus's book Higher Order Perl, along with his Memoize module show another example of goto &name in action as a means of facilitating the memoize() function which wraps an existing function in a caching wrapper and passes the memoized version back to the symbol table for future use. goto makes it all easy, as well as almost invisible.
Dave
In reply to Re^2: how to goto &sysread ?
by davido
in thread how to goto &sysread ?
by perl5ever
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |