#!/usr/bin/env perl use strict; use warnings; use Getopt::Long; use utf8::all; use Text::LexicalDiff; use Data::Dump qw/dump/; use feature qw/say/; #my ($cctx,$wa,$s,$w,$m,$lat1,$utf8,$ac,$ctx,$i,$maxwl,$maxdlen,$debug); my $options = {}; my $result = GetOptions ($options, 'cctx' , 'wa' , 's' , 'w' , 'm' , 'debug' , 'lat1' , 'utf8' , 'ac=s' , 'ctx' , 'i' , 'nonum' , 'maxwl=i' , 'maxdlen=i' , ); my $f1 = shift; my $f2 = shift or die usage(); my $oco = {}; my $mat = {}; handle_options($options); read_ac_file($options->{ac},$oco,$mat) if ( $options->{ac} and $options->{ac} ne "1" and -f $options->{ac}); my ($diff_fh,$text) = diff($f1,$f2,$options); proc_diff($diff_fh,$mat,$oco,$text,$options); while(@ARGV){ $f1 = shift; $f2 = shift or die usage(); my ($diff_fh,$text) = diff($f1,$f2,$options); proc_diff($diff_fh,$mat,$oco,$text,$options); } dump_cm($mat); dump_ac($mat,$oco,$options) if $options->{ac}; __END__ =head1 NAME lexdiff - lexical comparation of 2 files =head1 SYNOPSIS lexdiff [options] f1 f2 Options: -cctx same as -ctx -m -ac -s ==> char level changes -wa same as -w -ac -s ==> word level changes -s supress common tokens -w compare words -m compare characters -ac output to sort | uniq -c | sort -nr -ac=file starts with the previous acumulated results -ctx one (char or word) context (left and rigth) -i ignore case -debug keep temp. files -lat1 force reading input in ISO latin 1 encoding -utf8 force reading input is UTF-8 encoding -maxwl max word length (def: 8 for chars, 20 for words) -maxdlen max diff between length original and target -nonum ignore differences if just numbers are present =head1 DESCRIPTION lexdiff performs word by word or char by char comparations =head2 Example In order to calculate the differences between a set of files in the current directory and their correspondents in NEW/ folder, we can do: for a in *.txt; \ do lexdiff -w -ac=dif $a new/$a > aux; \ mv aux dif ; \ done =head1 AUTHOR Andre F. Santos, andrefs@cpan.org J.Joao Almeida, jj@di.uminho.pt =head1 SEE ALSO perl(1), diff(1) =cut __END__