Perl text color

I want to be able to compare two text strings and display the color difference. I tried String :: Diff but could not get the difference in display in color. I am using Windows with Active State perl 5, version 12.

Edit: ansi color etc. don't help me display color differences
Change: here is the result I want

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

some_diff_cmd ($ string1, $ string2);

The result I want (bold colors should be red)

### Lines do not match ####

string1 = This is line 1
string2 = This is line 2

+3
source share
1

?

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";
+5

All Articles