I have a hash of hashes that I maintain in a module that lives within a software configuration management system (ClearCase, but that is of no real import). I use the hash as a simple statistics database. A statistics collection and publishing script...

  1. uses the module
  2. updates the (in memory) hash with new statistics
  3. publishes the new statistics to some webpage
  4. checksout the module file from software CM
  5. stringifies the hash with Data::Dumper (Purity => 1)
  6. re-writes the module file using the stringified hash
  7. checksin the modified module file

What I (think I) want is to tie *all* the hashes in the hash of hashes so that they are always retrieved sorted, so that the output from Data::Dumper is always consistent. This would, I believe, allow the output of a diff against the previous version of a module file to consistently report accurate results.

Is there any easy way to declare that all the nested hashes in a structure will be sorted? BTW, I don't care one whit about the sort comparison subs - I just want consistency in the output. I am not that familiar with this kind of problem (nor really deeply with ties). Please also note that I do want to continue to maintain the hash as an entity declared and defined purely by the text within the module, if possible. I don't want to serialize it via some external database (using Storable or some such), since doing so would prevent module version diffs from being useful.

One other question - upon an eval of the stringified (by Data::Dumper) hash will the hashes be re-tied automagically or do I have to handle that myself somehow?

Conceptual guidance will be very appreciated. I can probably figure a reasonably acceptable approach myself, but I'd like to know the best and easiest way to do this.


In reply to Sort-Tying all hashes in a hash of hashes by welchavw

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.