http://www.perlmonks.org?node_id=635930


in reply to Perl class - how to create instance variable instead of class variable

You are almost there. What you have to keep in mind is that the
my $self = shift;
line in every member function gives you a blessed reference to the hash.

So instead of writing

$self{theValue}
you should write
$self -> {theValue}

Your modified code in full:

package Test; sub new { my $class = shift; my $self = {}; bless $self, $class; return $self; } sub getValue { my $self = shift; $self -> {theValue}; # note '->' } sub setValue { my $self = shift; my $value = shift; $self -> {theValue} = $value; # note '->' }