|
NAMEText::Diff3 - three way text comparison and merging.VERSION0.10SYNOPSIS# in default, this module does not export any symbol. use Text::Diff3; use Text::Diff3 qw(:all); use Text::Diff3 qw(diff3 merge diff); my $mytext = [map {chomp; $_} <$input0>]); my $original = [map {chomp; $_} <$input1>]); my $yourtext = [map {chomp; $_} <$input2>]); my $diff3 = diff3($mytext, $origial, $yourtext); for my $r (@{$diff3}) { printf "%s %d,%d %d,%d %d,%d\n", @{$r}; # lineno start from not zero but ONE! for my $lineno ($r->[1] .. $r->[2]) { print $mytext->[$lineno - 1], "\n"; } for my $lineno ($r->[3] .. $r->[4]) { print $yourtext->[$lineno - 1], "\n"; } for my $lineno ($r->[5] .. $r->[6]) { print $original->[$lineno - 1], "\n"; } } my $merge = merge($mytext, $origial, $yourtext); if ($merge->{conflict}) { print STDERR "conflict\n"; } for my $line (@{$merge->{body}}) { print "$line\n"; } my $diff = diff($original, $mytext); for my $r (@{$diff}) { printf "%s%s%s\n", $r->[1] >= $r->[2] ? $r->[1] : "$r->[1],$r->[2]", $r->[0], $r->[3] >= $r->[4] ? $r->[3] : "$r->[3],$r->[4]"; if ($r->[0] ne 'a') { # delete or change for my $lineno ($r->[1] .. $r->[2]) { print q{-}, $original->[$lineno - 1], "\n"; } } if ($r->[0] ne 'd') { # append or change for my $lineno ($r->[3] .. $r->[4]) { print q{+}, $mytext->[$lineno - 1], "\n"; } } } # component style (deprecated. no longer maintenance) use Text::Diff3 qw(:factory); DESCRIPTIONThis module provides you to compute difference sets between two or three texts ported from GNU diff3.c written by R. Smith.For users convenience, Text::Diff3 includes small diff procedure based on the P. Heckel's algorithm. On the other hands, many other systems use the popular Least Common Sequence (LCS) algorithm. The merits for each algorithm are case by case. In author's experience, two algorithms generate almost same results for small local changes in the text. In some cases, such as moving blocks of lines, it happened quite differences in results. FUNCTIONS
VARIABLE
SEE ALSOGNU/diffutils/2.7/diff3.cThree way file comparison program (diff3) for Project GNU. Copyright (C) 1988, 1989, 1992, 1993, 1994 Free Software Foundation, Inc. Written by Randy Smith P. Heckel. ``A technique for isolating differences between files.'' Communications of the ACM, Vol. 21, No. 4, page 264, April 1978. AUTHORMIZUTANI Tociyuki "<tociyuki@gmail.com>".LICENSE AND COPYRIGHTCopyright (C) 2011 MIZUTANI TociyukiThis program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version.
Visit the GSP FreeBSD Man Page Interface. |