1String::Diff(3)       User Contributed Perl Documentation      String::Diff(3)
2
3
4

NAME

6       String::Diff - Simple diff to String
7

SYNOPSIS

9         use String::Diff;
10         use String::Diff qw( diff_fully diff diff_merge diff_regexp );# export functions
11
12         # simple diff
13         my($old, $new) = String::Diff::diff('this is Perl', 'this is Ruby');
14         print "$old\n";# this is [Perl]
15         print "$new\n";# this is {Ruby}
16
17         my $diff = String::Diff::diff('this is Perl', 'this is Ruby');
18         print "$diff->[0]\n";# this is [Perl]
19         print "$diff->[1]\n";# this is {Ruby}
20
21         my $diff = String::Diff::diff('this is Perl', 'this is Ruby',
22             remove_open => '<del>',
23             remove_close => '</del>',
24             append_open => '<ins>',
25             append_close => '</ins>',
26         );
27         print "$diff->[0]\n";# this is <del>Perl</del>
28         print "$diff->[1]\n";# this is <ins>Ruby</ins>
29
30         # merged
31         my $diff = String::Diff::diff_merge('this is Perl', 'this is Ruby');
32         print "$diff\n";# this is [Perl]{Ruby}
33
34         my $diff = String::Diff::diff_merge('this is Perl', 'this is Ruby',
35             remove_open => '<del>',
36             remove_close => '</del>',
37             append_open => '<ins>',
38             append_close => '</ins>',
39         );
40         print "$diff\n";# this is <del>Perl</del><ins>Ruby</ins>
41
42         # change to default marks
43         %String::Diff::DEFAULT_MARKS = (
44             remove_open  => '<del>',
45             remove_close => '</del>',
46             append_open  => '<ins>',
47             append_close => '</ins>',
48             separator    => '&lt;-OLD|NEW-&gt;', # for diff_merge
49         );
50
51         # generated for regexp
52         my $diff = String::Diff::diff_regexp('this is Perl', 'this is Ruby');
53         print "$diff\n";# this\ is\ (?:Perl|Ruby)
54
55         # detailed list
56         my $diff = String::Diff::diff_fully('this is Perl', 'this is Ruby');
57         for my $line (@{ $diff->[0] }) {
58             print "$line->[0]: '$line->[1]'\n";
59         }
60         # u: 'this is '
61         # -: 'Perl'
62
63         for my $line (@{ $diff->[1] }) {
64             print "$line->[0]: '$line->[1]'\n";
65         }
66         # u: 'this is '
67         # +: 'Ruby'
68

DESCRIPTION

70       String::Diff is the difference of a consecutive string is made.  after
71       general diff is done, the difference in the line is searchable.
72
73       the mark of the addition and the deletion can be freely changed.  the
74       color is colored to the terminal with ANSI, using the HTML display it.
75
76       after the line is divided, diff is taken when 'linebreak' option is
77       specified.
78
79         my($old_string, $new_string) = String::Diff::diff_fully('this is Perl', 'this is Ruby', linebreak => 1);
80         my($old_string, $new_string) = String::Diff::diff('this is Perl', 'this is Ruby', linebreak => 1);
81         my $string = String::Diff::diff_merge('this is Perl', 'this is Ruby', linebreak => 1);
82         my $string = String::Diff::diff_regexp('this is Perl', 'this is Ruby', linebreak => 1);
83
84       In diff and diff_merge methods the mark of the difference can be
85       changed.
86
87         my $diff = String::Diff::diff('this is Perl', 'this is Ruby',{
88             remove_open => '<del>',
89             remove_close => '</del>',
90             append_open => '<ins>',
91             append_close => '</ins>',
92         });
93

METHODS

95       diff_fully
96             the list that divides diff according to the mark is returnd.
97
98               my($old_string, $new_string) = String::Diff::diff_fully('this is Perl', 'this is Ruby');
99
100       diff
101             abd the mark of the deletion and the addition is given to the string.
102
103       diff_merge
104             old and new string is merged with diff.
105
106       diff_regexp
107             the regular expression to which old string and new string are matched with regexp is returned.
108

AUTHOR

110       Kazuhiro Osawa <ko@yappo.ne.jp>
111

SEE ALSO

113       Algorithm::Diff
114

LICENSE

116       This library is free software; you can redistribute it and/or modify it
117       under the same terms as Perl itself.
118
119
120
121perl v5.12.0                      2008-10-27                   String::Diff(3)
Impressum