{ my %SELF = map { $_ => '' } qw( foo bar baz ); sub new { my $self = bless { %SELF } => shift; @$self{keys %SELF) = @{+shift}{keys %SELF}; return $self; } } #### { my %SELF = ( foo => 0, bar => "", baz => [], ); sub new { my $self = bless {} => shift; my %p = @_; croak("...") if keys %p > keys %SELF; # If given a bad key. $self->$_($p{$_}) foreach keys %p; # Lazy. Damn lazy. return $self; } } #### sub new { my $self = bless { foo => 0, bar => "", baz => [], this_should_not_be_touched_here => {}, } => shift; my %p = @_; $self->{$_} = delete $p{$_} for grep exists $p{$_} => qw/ foo bar baz /; # Note, this list doesn't equal keys(%$self). croak("Unknown parameters: @{[keys %p]}") if %p; return $self; }