2009/3/11 Dr.Ruud <rvtol+use...@isolution.nl>: > Dermot wrote: > >> I created a small Class, initially with Moose. When I wanted an >> instance of the class I would call `my $instance = new MyClass`; >> >> I then removed Moose and went for a standard Perl 00 constructor: >> >> sub new { >> my $class = shift; >> my $self = {}; >> $self->{config} = _get_config(); >> bless ($self, $class); >> return $self; >> } >> >> I haven't changed the way I created an instance, and it still works. I >> would have thought I would have to create instances now with >> >> my $instance = MyClass->new; >> >> Are both assignments legit? > > There is even a third way: > > MyClass::->new > > and a fourth way: > > MyClass::->new()
So do they all amount to the same thing? I can see that the 4th way would allow you to pass arguments. When you read the docs for modules they (all the one's I can recall) show either my $inst = new Some::Module; or my $inst = Some::Module->new; I thought there was some black art to allow you to make a constructor work with the first example. Dp. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/