package Test; sub new { my $class = shift; my $self = {}; bless $self, $class; return $self; } sub getValue { my $self = shift; $self{theValue}; } sub setValue { my $self = shift; my $value = shift; $self{theValue} = $value; } #### use Test; my $test = new Test; print "test is " .$test ."\n"; print "test getValue after new is " .$test->getValue() ."\n"; $test->setValue(1); print "test getValue after setValue(1) is ". $test->getValue() ."\n"; print "\n"; my $test1 = new Test; print "test1 is " .$test1 ."\n"; print "test1 getValue after new is " .$test1->getValue() ."\n"; #print "test getValue after test1->new is ". $test->getValue() ."\n"; $test1->setValue(2); print "test1 getValue after setValue(2) is " .$test1->getValue() ."\n"; print "test getValue after test1->setValue(2) is ". $test->getValue() ."\n"; #### test is Test=HASH(0x88fbc20) Use of uninitialized value in concatenation (.) or string at test.pl line 9. #expected test getValue after new is test getValue after setValue(1) is 1 test1 is Test=HASH(0x88fbde8) #different than test test1 getValue after new is 1 #wow, test1 "inherited" the value set by the test object test1 getValue after setValue(2) is 2 test getValue after test1->setValue(2) is 2 #and now test sees 2, instead of 1