- LICENSE AND COPYRIGHT
File::MultipleDiff - Compare multiple files
use File::MultipleDiff; multiple_file_diff ( <input_directory> , <file_names_pattern> , 'c|b' # c - colour, b - black/white , <max_digits_amount> );
Compares many files with each other. Writes comparison results into a symmetric matrix with one row and column per compared file. Each matrix element reports the number of differences between the files corresponding to the column and row.
If a directory "inp_directory" contains files "file1", ... "file5" and only these files, then the command
produces following output matrix:
--------------------------- | f f f f f | i i i i i | l l l l l | e e e e e | 1 2 3 4 5 --------------------------- file1 | 0 1 2 0 3 file2 | - 0 3 1 4 file3 | - - 0 2 5 file4 | - - - 0 3 file5 | - - - - 0
The entries of the matrix report the number of lines which differ between the two files. Thus, file1 and file4 are identical, while file2 and file5 have 4 differences.
Comparison of 2 objects is a commutative operation: its result does not depend on the order of operands.
That means, if A is equal to B, than B is equal to A, if A is not equal to B, that B is not equal to A. Thus the matrix is symmetric. See http://en.wikipedia.org/wiki/Symmetric_matrix.
For performance's sake a half of the matrix will be filled in.
fileA fileB ----- ----- line1 line1 line2 line3 line3 line4 line4 line5
Perl module Algorithm::Diff is used for file comparison. This module minimizes amount of differences and for the example above it detects 2 (not 3) differences between these files:
fileA fileB ----- ----- line1 line1 line2 1st difference line3 line3 line4 line4 line5 2nd difference
A basis of this minimization is the longest common subsequence (LCS) method, that is implemented in that module.
Have you noticed the catch above? The number of differences between two files is strictly speaking not commutative when Algorithm::Diff is used. Nevertheless I've decided to create a triangular matrix, as if a full matrix were indeed a symmetric matrix. This is acceptable for the implementation of this module as a "chaosmeter". Assume that you expect some configuration files on many computers to be identical and you want to check this. Hopefully most of them will be identical, but some of them are different. Zeroes in the matrix mean identical files and the identity check is indeed a commutative operation. Non-zeroes matrix elements mean the file contents differ and a level of chaos. The larger the matrix element, the larger distance between two files.
A known from mathematics metric or distance function is similar with a conversion, made by Algorithm::Diff. Absent commutativity is known as quasimetric. Quote from http://en.wikipedia.org/wiki/Metric_(mathematics)#Quasimetrics "Quasimetrics are common in real life. ... Example is a taxicab geometry topology having one-way streets, where a path from point A to point B comprises a different set of streets than a path from B to A."
multiple_file_diff ( <input_directory> # Directory, that contains all compared files; , <file_name_pattern> # Regular expression, optional parameter, # default value - all files in the input directory; , 'c|b' # Refers to output of comparison, optional. # c - colour, b - black/white output (b is default). # Prerequisite for usage of colour mode is that # terminal supports ANSI escape sequences. # More about is here # http://search.cpan.org/~rra/Term-ANSIColor-4.02/ANSIColor.pm ; , <max_digits_amount> ); # Max amount of digits in amounts of differences. # Optional parameter, default value is 2. # This parameter is self expandable and supports # amount of differences until 9999. # You can ignore the last parameter.
Only 1st parameter of this subroutine must be specified. Undefined or empty further parameters will be replaces by default values.
Mart E. Rivilis, firstname.lastname@example.org
Please report any bugs or feature requests to email@example.com, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=File-MultipleDiff. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
You can find documentation for this module with the perldoc command.
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
AnnoCPAN: Annotated CPAN documentation
Copyright 2013 Mart E. Rivilis. This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License (2.0).