in reply to OO Design Question with Hashes of Arrays
Hi ahackney,
While, I advise that you take vantage of the wisdom and words of kcott, I will say it's not bad to 'eat' on the boilerplate of perl OO intrinsic design.
..I am trying to make the following hash an attribute of the above class...
You could write subroutine, to 'set' and 'get', the value of the hash attribute like this:
..you get...{ package My::Sys; sub new { my $class = shift; my $self = { coreID => 0, isBpMaskError => 0, isVrrpErrors => 0, isSymPriorityErrors => 0, isSslProfileErrors => 0, isGlobalPortErrors => 0, isVipsinVipGroupsErrors => 0, isVipGroupErrors => 0, isSnatIpErrors => 0, isCodeVersionErrors => 0, aclsMissingFromMaster => {}, }; bless $self, $class; return $self; } sub set_acls{ my $self = shift; my $cot = 0; $self->{aclsMissingFromMaster}{"list ".++$cot} = $_ for @_; } sub get_acls{ my $self = shift; return $self->{aclsMissingFromMaster}; } } use Data::Dumper; my $sys = My::Sys->new(); my @arr = ([1..4],[5..8],); # set the attribute $sys->set_acls(@arr); { local $Data::Dumper::Sortkeys = 1; # get your values here print Dumper $sys->get_acls(); }
Just an example for you to see...$VAR1 = { 'list 1' => [ 1, 2, 3, 4 ], 'list 2' => [ 5, 6, 7, 8 ] };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: OO Design Question with Hashes of Arrays
by ahackney (Initiate) on Jun 26, 2013 at 13:23 UTC | |
by AnomalousMonk (Archbishop) on Jun 26, 2013 at 17:09 UTC |