i have written small class got getter , setter methods. 1 of properties hash.
sub getmydata { $objekt = shift; return $objekt->{mydata}; } sub setmydata { $objekt = shift; %mydata= shift; $objekt->{mydata} = \%mydata; }
if set value in skript access class:
my %test; $test{'apple'}='red'; $objekt = mynamespace::myclass->new; $objekt->setmydata(%test);
i thought can access value easy via:
my $data = $objekt->getmydata; print $data{'apple'};
i undef value.
can tell me what's wrong here , how can access getmydata , print value 'red'?
you missing dereference arrow. because put hashref (\%mydata
) in, reference out.
my $data = $objekt->getmydata; print $data->{'apple'}; # ^ # here
you need change assignment, because passing list setter, not reference. shift
scalar (single) values, %test
gets turned list (many values).
sub setmydata { $objekt = shift; %mydata = @_; $objekt->{mydata} = \%mydata; }
however, there few more issues code.
Comments
Post a Comment