in reply to diff of two hashes.
The first foreach creates a hash that contains all of the keys that are present in hash one and hash two who's contents dont match. It's data element is a list where $differences{$_}[0] is the data from hash one and $differences{$_}[1] is the data from hash two. It also has an entry for each key in hash one that does not appear in hash two, where $differences{$_}[1] is undefined.
The second foreach performs the inverse using the keys of hash two. except that when a key in hash two is not present in hash one, $differences{$_}[0] is undefined and $differences{$_}[1] contains the data from hash two. When it is complete %differences contains 3 types of record:
my %differences = (); foreach (keys %hash1) { $differences{$_}= [$hash1{$_}, $hash2{$_}] if $hash1{$_} ne $hash2 +{$_}; }; foreach (keys %hash2) { $differences{$_}= [$hash1{$_}, $hash2{$_}] if $hash1{$_} ne $hash2 +{$_}; };
Nuance
|
|---|