develooper Front page | perl.beginners | Postings from April 2010

references to operators?

Thread Next
From:
Tim Bowden
Date:
April 16, 2010 02:06
Subject:
references to operators?
Message ID:
1271408791.4530.25.camel@fangorn
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


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About