[EMAIL PROTECTED] wrote: > No. $self you'll usually see in a lot of Object Oriented applications. When a > subroutine is called using the -> operator ($mw = MainWindow->new, for > example) the first arguement passed to that subroutine is the name of the > package/class. So, $self is usually used to display this. So, a common constructor is > > sub new { > my ($self, %args) = @_; > return bless \%args, $self; > }
Not exactly. The traditional use for $self in Perl OO is as a reference to the object, not the class. Usually, you can just say $class for the class name. Also, most constructors I have seen do not use outside references for the hash. The return an anonymous hash declared within the constructor. Perl keeps such anonymous structures in scope as long as there is any reference to them in scope. So, a standard constructor would be a little more like: sub new { my $class = shift; my $self = {}; bless $self, $class; $self->initialize(@_); return $self; } You could call it like this: my $object = ObjectName->new($my_this, $my_that, $my_thuther); $object->do_special_object_stuff(); Of course, there is nothing keeping one from using the identifiers as you have them above. Neither new nor $self nor $class have any syntactic significance. I think the custom is a little closer to what I described, though. Joseph -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>