[Israel.pm] bless and AUTOLOAD

Gabor Szabo szabgab at gmail.com
Tue Sep 25 08:47:24 PDT 2007

On 9/25/07, Yona Shlomo <yona at cs.technion.ac.il> wrote:
> Thanks. This addresses my problems.
> Some questions:

I tried to find some pointers in perldoc but I could not come up
with anything comprehensive perlbot, perlsub and perltoot have
something about it

> 1. why our and not my for AUTOLOAD?
the real $AUTOLOAD is a package global so you need to treat it that way.
if you declare it with "my" you get a lexically scoped variable that
will hide the
real one.

> 2. why do I need to implement (even an empty) DESTROY sub?
because it is called when the object goes out of scope and if you have
an AUTOLOAD method it will catch it.
You can of course say
return if $AUTOLOAD =~ /::DESTROY$/;

in your AUTOLOAD method but I find it more descriptive to declare an empty
DESTROY method. Sometime I even add a comment saying

# to avoid triggering AUTOLOAD

Perl Training Israel

More information about the Perl mailing list