in reply to confusing constructor code
This constructor is written in a confusing way, so you're right to be confused about it. About your questions:
Whether or how that can make sense has been discussed here and elsewhere. In most cases, you can just leave it out.my $obj = My::Class->new(...); my $other_obj = $obj->new(...);
My::Class->new("a","b");
is the same as
My::Class::new("My::Class","a","b");
except that inheritance is not respected in the second case.
$self = { @_ }; # or %$self = @_;
In short, the whole constructor could have been written as:
sub new { my ($class,%args) = @_; my $self = \%args; bless $self, ref($class)||$class; };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: confusing constructor code
by Burak (Chaplain) on Jul 01, 2008 at 07:47 UTC | |
by Corion (Patriarch) on Jul 01, 2008 at 07:52 UTC | |
by Burak (Chaplain) on Jul 01, 2008 at 08:07 UTC | |
by dragonchild (Archbishop) on Jul 01, 2008 at 12:55 UTC |