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.


In reply to Perl Data Structure Validation Part 2 by zerohero

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.