# install in the symbol table of the class of
# the invocant under the proper name
#
*{$AUTOLOAD} = $sub;
On 29/10/2020 14:48, Rainer Weikusat wrote:
# install in the symbol table of the class of
# the invocant under the proper name
#
*{$AUTOLOAD} = $sub;
This is Perl witchcraft, but I followed it and am much better
informed; it's really clever.
One thing, though: in the statement above you're telling Perl that
instead of the AUTOLOAD subroutine it should go straight to the sub
that you built and compiled: I get that.
But I thought $AUTOLOAD was the variable (defined in all the examples
I've seen with "our $AUTOLOAD") not the subroutine? I'm wrong,
plainly, but why?
"Rainer" == Rainer Weikusat <rweikusat@talktalk.net> writes:
"Rainer" == Rainer Weikusat <rweikusat@talktalk.net> writes:
Rainer> $AUTOLOAD =~ /([^:]+)$/, $sub = $1; # determine subroutine Rainer> name
This is bad style and potentionally dangerous. If the match fails, $1
is the *previous* $1, leading to bugs I've seen in the wild. Do this instead:
my ($sub) = $AUTOLOAD =~ /([^:]+)$/ or die "bad $AUTOLOAD value\n";
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 493 |
Nodes: | 16 (2 / 14) |
Uptime: | 183:29:01 |
Calls: | 9,705 |
Files: | 13,737 |
Messages: | 6,179,547 |