#!/usr/bin/env perl use strict; use warnings; use Inline::Files; use XML::Simple qw{:strict}; my %xml_hash = (Data => {}); my $xml_data = $xml_hash{Data}; my (%db1, %db2); while () { my ($root, $table, $key) = split; push @{$db1{$root}{$table}}, $key; } while () { my ($root, $table, $key) = split; push @{$db2{$root}{$table}}, $key; } while () { my ($root, $table, $key, $col, $old, $new) = split; $xml_data->{$root}{$table}{NEW1}{KEY} = $db1{$root}{$table} if exists $db1{$root}{$table}; $xml_data->{$root}{$table}{NEW2}{KEY} = $db2{$root}{$table} if exists $db2{$root}{$table}; $xml_data->{$root}{$table}{MODIFIED}{KEY}{$key}{$col}{oldvalue} = [$old]; $xml_data->{$root}{$table}{MODIFIED}{KEY}{$key}{$col}{newvalue} = [$new]; } print XMLout(\%xml_hash, KeepRoot => 1, KeyAttr => {KEY => 'name'}); __DIFF__ Root1 TBLA KEY1 COLA A B Root1 TBLA KEY1 COLB D E Root1 TBLA KEY3 COLX M N Root2 TBLB KEY4 COLX M N Root2 TBLB KEY4 COLD A B Root3 TBLC KEY5 COLD A B __DB1__ Root1 TBLA KEY6 Root2 TBLB KEY7 Root3 TBLC KEY8 __DB2__ Root1 TBLA KEY9 Root1 TBLA KEY10 Root3 TBLC KEY11 #### $ pm_xml_db_diff.pl B A E D N M KEY6 KEY9 KEY10 B A N M KEY7 B A KEY8 KEY11