I've got a nested hash data structure, and I want to create tests for
many of the attributes within that data structure, but I'm not sure of
the best way to do that.  

Example:

my $dataStructure = {'GroupA'=>{
    'element1'=>{
      'attrib1'=>'someValue', 'attrib2'=>'otherValue'},
    'element2'=>{
      'attrib1'=>'someValue', 'attrib2'=>'otherValue'},
  },
  'GroupB'=>{
    'element1'=>{
      'attrib1'=>'someValue', 'attrib2'=>'otherValue'},
    'element2'=>{
      'attrib1'=>'someValue', 'attrib2'=>'otherValue'},
  },
};

It doesn't take too many 'Groups' or 'elements' before testing for
sensible 'attrib' values becomes very unwieldy, particularly as each
'Group' will have slightly different 'elements'.  Rather than creating
some huge difficult to maintain 'if elsif' tree to test relevant
attributes, I was hoping there was some way I could create a generic if
statement, and put the tests within the data structure by adding
something like:

'test_operator' => '=', 'test_value' => 'somevalue'

at the 'attrib' level of the data structure.  Then the if statement
would look something like..

if ($refToAttrib $refToOperator $refToTestValue){...

The $refToOperator is the problem bit.  Can that be done, or is there a
better way to solve the problem?

Thanks,
Tim Bowden


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to