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};
}
}
}