in reply to OO Perl: after it creates 2nd object overwrites hash from the first

_attribute_default returns the same references every time, as the default attributes of new objects. Every $self->{_hash} refers to the same hash by default. You reassign the _data element by providing an initial value, but you don't reassign the _hash element.

Watch it happen by adding some print statements to your constructor:

# Constructor sub new { my ( $class, %arg ) = @_; my $self = bless {}, $class; $self->_arg_exist(%arg); # Check if all given args are ok # Set the attributes for the provided arguments foreach my $attribute ( $self->_all_attributes() ) { my ($argument) = ( $attribute =~ /^_(.*)/ ); # Initilize to defaults $self->{$attribute} = $self->_attribute_default($attribute); # Override defaults with arguments if ( exists $arg{$argument} ) { print STDERR "Overriding $attribute with $argument ($arg{$argument})\n +"; $self->{$attribute} = $arg{$argument}; } } foreach my $k (keys %$self) { print STDERR "$k: $self->{$k}\n"; } # Empty the hash loci %{$self->{_hash}} = (); # Getting the data from the array # and storing the information in the hash $self->_get_hash (); return $self; }

Caution: Contents may have been coded under pressure.