in reply to Comparing Lines within a Word List
Regular expression are not the best tool to do what you want actually. Not because your problem is impossible or even difficult to solve with regular expressions, but because there is a much better option. The bitwise xor operator "^" will yield a 0 anywhere the two strings are equal, but 1 for every bit that is different between the two.
With that, and maybe the use of ord (you don't actually need it but it may help make things clearer) you should be able to do what you want.my $first = "Fool"; my $second = "Foot"; my $diff = ($first ^ $second); print unpack "B*", $diff; # Print the binary representation of the dif +ference my @diff_char = split //, $diff; # get a char by char difference.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Comparing Lines within a Word List
by AnomalousMonk (Archbishop) on Apr 26, 2016 at 23:02 UTC | |
by dominick_t (Acolyte) on Apr 27, 2016 at 03:42 UTC | |
by AnomalousMonk (Archbishop) on Apr 27, 2016 at 16:22 UTC | |
by dominick_t (Acolyte) on Apr 27, 2016 at 16:39 UTC | |
by Eily (Monsignor) on Apr 27, 2016 at 18:51 UTC |