NAME
String::ShowDiff - Perl extension to help visualize differences between strings
SYNOPSIS
use String::ShowDiff qw/ansi_colored_diff/;
print ansi_colored_diff("abcehjlmnp", "bcdefjklmrst");
# or a bit more detailed:
my %options = ('u' => 'reset',
'+' => 'on_green',
'-' => 'on_red');
print ansi_colored_diff($oldstring, $newstring, \%options);
DESCRIPTION
This module is a wrapper around the diff algorithm from the module Algorithm::Diff
. It's job is to simplify a visualization of the differences of each strings.
Compared to the many other Diff modules, the output is neither in diff
-style nor are the recognised differences on line or word boundaries, they are at character level.
FUNCTIONS
- ansi_colored_diff $string, $changed_string, $options_hash;
-
This method compares
$string
with$changed_string
and returns a string for an output on an ANSI terminal. Removed characters from$string
are shown by default with a red background, while added characters to$changed_string
are shown by default with a green background (the unchanged characters are shown with the default values for the terminal).The
$options_hash
allows you to set the colors for the output. The variable is a reference to a hash with three optional keys ('u' for the color of the unchanged parts, '-' for the removed parts and '+' for the added ones). The default values for the options are:my $default_options = { 'u' => 'reset', '-' => 'on_red', '+' => 'on_green' };
The specified colors must follow the conventions for the
colored
method of Term::ANSIColor. Please read its documentation for details.
EXPORT
None by default.
SEE ALSO
Algorithm::Diff, Text::Diff, Text::ParagraphDiff, Test::Differences
AUTHOR
Janek Schleicher, <bigj@kamelfreund.de>
COPYRIGHT AND LICENSE
Copyright 2003 by Janek Schleicher
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.