perl - How to get the value of class member? -
there following class:
package myclass; use strict; use warnings; sub new { $class = shift(); $self = { _class_member => "default" }; bless ($self, $class); return $self; }
how can set/get value of _class_member
?
i tried following code:
sub set_name { $self = shift(); $self->_class_member = shift(); }
but following error:
can't locate object method "_class_member" via package "myclass" ...
what doing wrong here?
$self
blessed hash. unless or original author provided method _class_member
, there's no such method.
you can however, "reach in" hash access it:
$self->{'_class_member'} = shift;
this not recommended practice instance values because it's easy type:
$self->{'_vlass_member'} = shift;
without complaint. hence value of accessors.
Comments
Post a Comment