What about "o" in owl and dog? And what about backward difference? This is not exactly what String::Diff do. If you only want to get characters from second string which doesn't match to the characters in the first string it may be quite simple to implement, but I wouldn't call this a difference.
Update: maybe you'll find the following (quick and dirty, sorry, I don't yet have my tea) code useful:
use strict; use warnings; use 5.010; my $pair1 = ['abcdf', 'abcde']; my $pair2 = ['Lazy dog', 'Loony owl']; for my $ref ($pair1, $pair2) { say "Words: ", join ", ", @$ref; say "Diff: ", diff(@$ref); say "Diff (rev): ", diff(reverse @$ref); } sub diff { my ($str1, $str2) = @_; my @arr1 = split //, $str1; my @arr2 = split //, $str2; my @res = (); while ($_ = shift @arr2) { my $ch = shift @arr1 or last; push @res, $ch unless $ch eq $_; } push @res, @arr1; join "", @res; } __END__ Words: abcdf, abcde Diff: f Diff (rev): e Words: Lazy dog, Loony owl Diff: azy dg Diff (rev): oony wl
In reply to Re^5: Comparing $_ --- before/after
by zwon
in thread Comparing $_ --- before/after
by mrc
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |