perl compare two strings and highlight mismatch characters -
string1 = "aaabbbbbcccccddddd" string2 = "aeabbbbbcceccddddd" output. mismatch (in case e) replaced html tags around e color it.
a**e**abbbbbcc**e**ccddddd what tried far: xor, diff , substr. first need find indices replace indices pattern.
use strict; use warnings; $string1 = 'aaabbbbbcccccddddd'; $string2 = 'aeabbbbbcceccddddd'; $result = ''; for(0 .. length($string1)) { $char = substr($string2, $_, 1); if($char ne substr($string1, $_, 1)) { $result .= "**$char**"; } else { $result .= $char; } } print $result; prints a**e**abbbbbcc**e**ccddddd
tested somewhat. may contain errors.
Comments
Post a Comment