Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Perl Data Structure Validation Part 2by zerohero (Monk) |
on Apr 16, 2009 at 19:48 UTC ( [id://758059]=perlquestion: print w/replies, xml ) | Need Help?? |
zerohero has asked for the wisdom of the Perl Monks concerning the following question: I asked a question earlier about validating perl "hierarchical data structures" and got good answers on how to do part of this. It turns out that Rx (Data::Rx) looks like a good choice (getting good error messages out seems like a feature that is currently being implemented). Kwalify looked similar and older, but the Rx site and documentation seemed a little more compelling. I'll have to try the code and find out. There is one more aspect of data validity that validators like Rx and Kwalify do not handle. These usually relate to correlating things between structures. For example, perhaps a set of keys is dependent on a set of keys in another part of the structure. I find for this type of checking that using an algorithmic approach combined with "something like XPath" to be the most readable and succinct. XPath lets you easily choose sets of things within a hierarchical structure. I tend to think of XPath like "regexp for trees" although this is an imperfect analogy. Is there a perl library that does something like "XPath" for perl structures? This would let one give a "path", which would be a string expression which describes some set of nodes. It would return the nodes and then give you set operations on those. This eliminates all of the messy traversal code, collapsing it to single statements.
Back to
Seekers of Perl Wisdom
|
|