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:

{ 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(); }
..you get...
$VAR1 = { 'list 1' => [ 1, 2, 3, 4 ], 'list 2' => [ 5, 6, 7, 8 ] };
Just an example for you to see...
You might want to check some other documentation like perlobj, perlootut.

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

    Thanks for the input everyone. I do understand (somewhat) hashes of arrays data structure.

    I have looked into moose and others as suggested. My needs are so small at this point (I'm almost done) that I think I'm going to keep hacking away at the base perl system.

    Anonymous Monk, thank you so much. This was just what I needed and it works exactly as you demonstrated. I am ignorant of some of the syntax that you used and I was wondering if you could point me to an article that explains the syntax usage? I googled and could not find anyone using the syntax quite this way in my searches.

    Specifically...

     = $_ for @_;

    I'm guessing this is shorthand for a for loop, but, again, my searches have been fruitless and the man pages have not been helpful.

    Thank you again monks for the assistance!

      ... an article that explains the syntax usage ...
       = $_ for @_;
      I'm guessing this is shorthand for a for loop ...

      This is the statement modifier form of a for-loop. It iterates over the elements of a  LIST and 'topicalizes' (or aliases with localization) the default scalar  $_ (see perlvar) to each element in turn. Because  $_ is aliased, elements of an array can be altered "in place", which can be very helpful, even essential, in dealing with large arrays.

      >perl -wMstrict -le "$_ = 'same as it ever was'; ;; my @ra = (1, 2, 3, 4); ;; $_ = $_ + 990 for @ra; print qq{@ra}; ;; print 880 + $_ for 1, 2, 3, 4; ;; print $_; " 991 992 993 994 881 882 883 884 same as it ever was

      (For some insight into the difference between a list and an array, try executing the statement
          $_ = $_ + 990 for 1, 2, 3, 4;
      instead.)