Perl文本差异颜色

sou*_*ser 3 string perl diff colors

我希望能够比较两个文本字符串并显示颜色的差异.我尝试过String :: Diff但是无法区分显示颜色.我使用Windows与Active State perl 5,版本12.

编辑:ansi颜色等没有帮助我显示颜色的差异
编辑:这是我想要的结果

$string1 = "This is string 1" ;
$string2 = "This is string 2" ;

some_diff_cmd($string1,$string2) ;

我想要的输出(以粗体显示的条目应为彩色,表示红色)

###字符串不匹配####

string1 =这是字符串1
string2 =这是字符串2

rai*_*7ow 5

这个怎么样?

use Win32::Console::ANSI;
use String::Diff qw( diff );

my @strings = (
  'This is string 1', 'This is string 2'
);

my $BOLD_RED_MARK = "\e[1;31m"; # or \e[0;31m, if bold is not required
my $RESET_MARK    = "\e[0m";

my $diff = String::Diff::diff(@strings,
   remove_open  => $BOLD_RED_SIGN,
   remove_close => $RESET_SIGN,
   append_open  => $BOLD_RED_SIGN,
   append_close => $RESET_SIGN,
);

print $diff->[0], "\n";
print $diff->[1], "\n";
Run Code Online (Sandbox Code Playgroud)