in reply to Perl Object Initilization

The easy way to do this is with Moose:

package Obj; use Moose; has 'a', is => 'ro', default => 10; package main; my $obj = Obj->new( a => 10 );

... though if you must write your own initializer, the easiest and clearest and probably most efficient way is:

sub initialize { my $self = shift; while (my ($key, $value) = splice @_, 0, 2)) { $self->{$key} = $value; } }

Replies are listed 'Best First'.
Re^2: Perl Object Initialization
by eye (Chaplain) on Jun 11, 2011 at 14:35 UTC
    Additionally, Moose offers mechanisms that can be used for object initialization (BUILD) and per attribute initialization (builder). Attributes may also be "lazy" so that they will not be initialized until they are needed (this is discussed at length in subsequent comments). Links are to the Moose documentation.