Perl Need to Compare Two Data Structures and Return Differences
I have two data structures with a mix of hashes and arrays. How can I compare the two data structures and return their differences, something lik开发者_如何转开发e perl's Test::Harness module, but I don't want to actually run a unit test. ...or is there a way to tun Test::Harness without actually running a unit test?
Perl Monks says that Test::Deep, Data::Compare, and Data::Match are your friends. Those packages don't seem to be geared towards producing detailed diffs but you might be able to hack in a callback to keep track of the precise differences.
Test::Deep::NoTest (from Test::Deep) might be what you are looking for, giving the functions of Test::Deep outside a test script (eq_deeply, cmp_deeply, etc). Look at using deep_diag() to see what the differences are.
Data::Compare - also gives functions returning boolean responses (rather like using cmp
on the command line for files), but (from memory) is harder to return what those differences are.
I used the former most recently, probably to get the deep_diag() details that Data::Compare didn't provide, but I haven't tried parsing the response.
精彩评论