in reply to Death to auto-vivification

You may find Hash::Util or Readonly interesting. I haven't used either but I'm sure other monks could chime in on their pros and cons. A Super Search might point you in the right direction, too.

Replies are listed 'Best First'.
Re^2: Death to auto-vivification
by doom (Deacon) on Mar 04, 2008 at 06:38 UTC
    I'm a fan of Hash::Util when working with hash-based objects, myself. I tend to use init routines that look like this (to make it impossible to accidentally create a hashkey that's not supposed to be there):
    use Hash::Util qw( lock_keys unlock_keys ); sub init { my $self = shift; my $args = shift; unlock_keys( %{ $self } ); my @attributes = qw( something_or_other another_something ); foreach my $field (@attributes) { $ATTRIBUTES{ $field } = 1; $self->{ $field } = $args->{ $field }; } lock_keys( %{ $self } ); return $self; }