in reply to dereference hash key object in access method

What concept is it that I am not understanding?

Several, and there are a number of things that you ought to do to make your code clearer, more robust and easier to maintain.

First off, if you are going to accept a number of parameters in a sub you should:

sub mySub { my ($param1, $param2, %bunchOfOptions) = @_;

so that it is clear at a glance what the parameters are that are expected. Although Perl allows great freedom to pass parameters using a vast range of techniques (potentially in the same sub), it also allows you a wonderful range of techniques for shooting yourself in the foot. Make an effort to use a consistent parameter passing technique and your code will work much more reliably.

The first major concept you have missed is that methods intended to be called on blessed references generally must be called on blessed references. In your constructor you call add_numbers before you even have a blessed reference let alone call it using the blessed reference. In fact there are very few occasions when you should call a sub using & in any case.

The second important (and related) concept is that the object is the reference once it has been blessed. $ref contains the object. With your current design you the bless line should precede the add_numbers call.

You ought to use explicit return values rather than relying on the last lvalue. It makes it much clearer that you are returning the value by intent rather than as a side effect. Putting it all together your code should look something like:

use strict; use warnings; package Music; sub new { my ($class, $number1) = @_; my $self = bless {"Number_one" => $number1}, $class; $self->{"Number_two"} = $self->add_numbers (); return $self; } sub add_numbers { my ($self) = @_; return $self->{"Number_one"}; } sub display_values { my ($self) = @_; print "$self->{'Number_one'}\n$self->{'Number_two'}\n"; } 1;

Perl reduces RSI - it saves typing