I have two deep hashes (represented below) - I want to compare the two against each other to create a database difference report. So when I'm finished (against the code below), I would know that I have two column diffs between them ('SOME_DATE' has different type and 'CYCLE_DATE' has different nullable values), as well as I have an extra column in the second hash. I've been using the examples here to walk through the hashes, but I can't see how to effectively compare them / place all the differences into a third array/hash: "differences". Thank you for any/all help that you can provide!
#!/usr/bin/perl -w use strict; use Data::Dumper; my %hash = ( TABLE_NAME => { COLUMN_NAME => { 'CYCLE_DATE' => { TYPE => 'VARCHAR2(20)', NULLABLE => 'N' +}, 'SOME_DATE' => { TYPE => 'DATE', NULLABLE => 'N' +}, 'AMITRUE' => { TYPE => 'BOOLEAN', NULLABLE => 'N' +} } } ); my %hash2 = ( TABLE_NAME => { COLUMN_NAME => { 'CYCLE_DATE' => { TYPE => 'VARCHAR2(20)', NULLABLE => 'Y' +}, 'SOME_DATE' => { TYPE => 'SOMEGUY', NULLABLE => 'N' +}, 'AMITRUE' => { TYPE => 'BOOLEAN', NULLABLE => 'N' +}, 'THE_DUDE' => { TYPE => 'VARCHAR2(10)', NULLABLE => 'Y' +} } } ); # works for walking single hash - have just started # trying to figure out how I'd do both. walk_hash(\%hash, \%hash2); sub walk_hash { my ($h1, $h2) = shift; foreach my $key (keys %$h) { if( ref $h->{$key}) { walk_hash( $h->{$key} ); } else { print $h->{$key}; } } }

In reply to Comparing two deep hash of hashes by TJRandall

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.