I frequently see statements like
*{$AUTOLOAD} = \&foobar; # under no strict 'refs'
but I don't understand the need for curly brackets in the LHS
expression. Why not simply
*$AUTOLOAD = \&foobar;
?
TIA!
jill
--
To s&e^n]d me m~a}i]l r%e*m?o\v[e bit from my a|d)d:r{e:s]s.
2. catch all method... e.g perl's autoload
3. Python's __getattr__, Perl's autoload, Ruby's method_missing, and Smalltalk's #doesNotUnderstand
4. Python's __getattr__, Perl's autoload, Ruby's method_missing, and Smalltalk's #doesNotUnderstand
5. SUPER::AUTOLOAD(@_) -- will this work? With $AUTOLOAD?
On Dec 19, 4:01 pm, Dodger < XXXX@XXXXX.COM > wrote a question and
then shortly thereafter answered it himself.
It appears to work. I made a small test script like so:
use strict;
my $bar = new Bar;
$bar->{thing} = 1;
print "\$bar->thing = ", $bar->thing, "\n";
print "Trying Bar AUTOLOAD specifically\n";
$bar->do_bar_AUTOLOAD(1, 2, 3);
print "\n";
print "Trying inherited AUTOLOAD\n";
$bar->do_foo_AUTOLOAD(4, 5, 6);
print "\n";
package Foo;
use strict;
our $AUTOLOAD;
sub new {
my $pkg = shift;
my $class = ref $pkg || $pkg;
my $obj = {};
bless $obj, $class;
return $obj
}
sub AUTOLOAD {
my $obj = shift;
my $method = $AUTOLOAD;
$method =~ s/^.*://;
print "AUTOLOAD of Foo\n";
print "method: $method\n";
print "args: ", join('. ', @_), "\n";
}
package Bar;
use strict;
use vars('@ISA');
BEGIN {
push @ISA,('Foo');
}
our $AUTOLOAD;
sub AUTOLOAD {
my $obj = shift;
my $method = $AUTOLOAD;
$method =~ s/.*://;
print "method: $method\n";
if ($method eq 'do_bar_AUTOLOAD') {
print "AUTOLOAD of Bar\n";
print "method: $method\n";
print "args: ", join('. ', @_), "\n";
}
elsif (exists $obj->{$method}) {
return "(Bar sez) $obj->{$method}";
}
else {
$obj->SUPER::AUTOLOAD(@_);
}
}
and my results came back as:
method: thing
$bar->thing = (Bar sez) 1
Trying Bar AUTOLOAD specifically
method: do_bar_AUTOLOAD
AUTOLOAD of Bar
method: do_bar_AUTOLOAD
args: 1. 2. 3
Trying inherited AUTOLOAD
method: do_foo_AUTOLOAD
AUTOLOAD of Foo
method:
args: 4. 5. 6
method: DESTROY
AUTOLOAD of Foo
method:
args:
So it appears that this trick will not work unless I specifically
assign to Foo::AUTOLOAD before calling it...
I tried it two ways:
else {
$SUPER::AUTOLOAD = $AUTOLOAD;
$obj->SUPER::AUTOLOAD(@_);
}
does NOT work, which seems odd...
because
else {
$Foo::AUTOLOAD = $AUTOLOAD;
$obj->SUPER::AUTOLOAD(@_);
}
DOES work...
So, I know how to do it now, but... I'm still unclear on one part...
Can anyone explain why I can't set the $AUTOLOAD in Foo with
$SUPER::AUTOLOAD instead of $Foo::AUTOLOAD if I can successfully call
SUPER::AUTOLOAD() instead of having to specify Foo::AUTOLOAD() ?
6. I am looking for PERL coder from Romania, Bulgaria, Russia or India - Perl
7. I am looking for a free perl compiler.
Hi, guys, I am looking for a free perl compiler. I tried PDK-Pro-6.0 from ActiveState. It works pretty well. But it's not free. Where can I get a free perl compiler, as powerful as PDK-Pro-6.0 from ActiveState? Thanks in advance. Best wishes, Xun -- Best wishes, Xun