Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Setting maximum hunk size in Algorithm::Diff

by tybalt89 (Curate)
on Jan 13, 2018 at 12:14 UTC ( #1207193=note: print w/replies, xml ) Need Help??


in reply to Setting maximum hunk size in Algorithm::Diff

Just diff by character. Something like this ?

#!/usr/bin/perl # http://perlmonks.org/?node_id=1207184 use strict; use warnings; use Algorithm::Diff qw(traverse_sequences); use Term::ANSIColor; my $file1 = <<'END'; #!/usr/bin/perl use Algorithm::Diff qw(traverse_sequences); use Term::ANSIColor; use strict; use warnings; # line in both files # line only in file1 my @from = split //, shift // 'this is the left string'; my @to = split //, shift // 'this is the right string'; traverse_sequences( \@from, \@to, { MATCH => sub {print $from[shift()]}, DISCARD_A => sub {print color('red'), $from[shift()], color 'reset'} +, DISCARD_B => sub {print color('green'), $to[pop()], color 'reset'}, } ); print "\n"; END my $file2 = <<'END'; #!/usr/bin/perl use Algorithm::Diff qw(traverse_sequences); use Term::ANSIColor; use warnings; use strict; # line in both files my @from = split //, shift // 'this is the source string'; my @to = split //, shift // 'this is the target string'; # line only in file2 traverse_sequences( \@from, \@to, { MATCH => sub {print $from[shift()]}, DISCARD_A => sub {print color('darkred'), $from[shift()], color 'res +et'}, DISCARD_B => sub {print color('cyan'), $to[pop()], color 'reset'}, } ); print "\n"; END my @from = split //, $file1; my @to = split //, $file2; traverse_sequences( \@from, \@to, { MATCH => sub {print $from[shift()]}, DISCARD_A => sub {print color('red'), $from[shift()], color 'reset'} +, DISCARD_B => sub {print color('green'), $to[pop()], color 'reset'}, } ); print "\n";

Output not shown because it contains ANSI color sequences. Run in a terminal (like linux console or xterm) that can handle them.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1207193]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2018-01-21 02:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How did you see in the new year?










    Results (227 votes). Check out past polls.

    Notices?