in reply to Re: Re: hash as an object property
in thread hash as an object property
Here's a generic get/set access method for instance data that's stored in a hash in an object that's implemented as a blessed hash.
It takes two mandatory arguments, the name of the data item that you're trying to access and the key in that hash that you want to get of set. If it's passed a third (optional) parameter then it uses that as the new value. It always returns the value.
sub hash_accessor { my $self = shift; my ($data, $key) = (shift, shift); if (@ARGV) { $self->{$data}{$key} = shift; } return $self->{$data}{$key}; }
Blessed Be
The Pixel
|
|---|