in reply to Re: Perl Object Initilization
in thread Perl Object Initilization
Here yuo are using the fact that an even-sized list can simply be assigned to a new hash to populate it ( which is what you always do when you say my %hash=( key1 => value2 ) as '=>' is just a glorified comma). I would also agree that, particularly in this case, a separate init method is not needed, because you are just assigning values to attributes and that can all be done when you construct the hash that you then bless in the 'new' method.sub init { my $self = shift; my %args = @_; while (my ($attribute, $value) = each %args){ $self->{$attribute} = $value; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Perl Object Initilization
by chromatic (Archbishop) on Jun 11, 2011 at 16:06 UTC | |
by tospo (Hermit) on Jun 14, 2011 at 12:22 UTC | |
|
Re^3: Perl Object Initilization
by PyrexKidd (Monk) on Jun 11, 2011 at 23:32 UTC |