On Tue, 5 Jun 2001, Alan F. Larimer, Jr. wrote:
> 1) After reading the perltoot manpage and most of the perlobj manpage, I am
> left with a question of "properness." Should instance methods always only
> return references? In the perltoot manpage it shows an instance method
> returning an array instead of the reference to it. Then pushing that onto an
> array (in main) to be used later. Wouldn't that be less effecient
> (memory/speed) than just passing back the reference?
Not necessarily. You might want to have your instance method do something
different when used in a list context versus being used in a scalar
context. If you used a reference, the user of your class would have to do
some funny things to go into a list context versus a scalar context. If
you let your method handle that, the user of your class will be happier.
> 2) DESTROY I'm not sure I understand how this is used. I do understand the
> purpose. For example (from perltoot manpage), a class variable is storing the
> poulation of a Person class (increased everytime new is called). There is a
> DESTROY function/subroutine for accounting for a loss of an object, decreasing
> the population. Does one using the class have to specifically call the
> DESTROY, or is that called when the reference to an object is gone? (In case
> you couldn't tell, it really has me lost.)
DESTROY should never be called explicitly (although you can) -- it
functions similarly to C++ destructors. It is called implicitly when the
last reference to the object goes away. In most cases, creating a
destructor is probably not necessary unless you need to close filehandles,
socket connections, modify class data (as in your example), etc.
-- Brett
Brett W. McCoy
Software Engineer
Broadsoft, Inc.
240-364-5225
[EMAIL PROTECTED]