in reply to What is the use of getter and setter

They hide the internal structure of the object from the caller. This allows the internal structure to be changed without breaking a lot of unrelated code. This is called encapsulation.

For example, instead of doing

$obj->{key} = 'val';

you'd do

$obj->key('val');

The latter might simply do the same thing as the former. Or maybe it adds error checking. At the very least, it gives the *option* to add error checking without breaking code.