Text::Diff3

Three way text comparison and merging
Download

Text::Diff3 Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • MIZUTANI Tociyuki
  • Publisher web site:
  • http://search.cpan.org/~tociyuki/Text-Diff3-0.06/lib/Text/Diff3/Diff3.pm

Text::Diff3 Tags


Text::Diff3 Description

Three way text comparison and merging Text::Diff3 is a Perl module that provides a way to compute difference sets between two or three texts ported from GNU diff3.c written by R. Smith.For users convenience, Text::Diff3::Lite includes small diff 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.SYNOPSIS # in default, this module does not export any symbol. use Text::Diff3; # function style introduced from VERSION 0.08 use Text::Diff3 qw(:all); use Text::Diff3 qw(diff3 merge diff); # component style is no longer maintenance. use Text::Diff3 qw(:factory); my $mytext = ); my $original = ); my $yourtext = ); # function style introduced from VERSION 0.08 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-> .. $r->) { print $mytext->, "\n"; } for my $lineno ($r-> .. $r->) { print $yourtext->, "\n"; } for my $lineno ($r-> .. $r->) { print $original->, "\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-> >= $r-> ? $r-> : "$r->,$r->", $r->, $r-> >= $r-> ? $r-> : "$r->,$r->"; if ($r-> ne 'a') { # delete or change for my $lineno ($r-> .. $r->) { print q{-}, $original->, "\n"; } } if ($r->type ne 'd') { # append or change for my $lineno ($r-> .. $r->) { print q{+}, $mytext->, "\n"; } } }); # component style is no longer maintenance. my $f = Text::Diff3::Factory->new; my $mytext = $f->create_text(); my $original = $f->create_text(); my $yourtext = $f->create_text(); my $p3 = $f->create_diff3; my $diff3 = $p3->diff3($mytext, $original, $yourtext); for my $r (@{$diff3->list}) { print $r->as_string, "\n"; # 1 2,3 4,5 6,7 print $mytext->as_string_range($r->range0); print $yourtext->as_string_range($r->range1); print $original->as_string_range($r->range2); } my $p2 = $f->create_diff; my $diff = $p2->diff($original, $mytext); for my $r (@{$diff->list}) { print $r->as_string, "\n"; # 100,102c104,110 print $original->as_string_range($r->rangeA); print $mytext->as_string_range($r->rangeB); } Requirements: · Perl


Text::Diff3 Related Software