in reply to Re: Comparing Lines within a Word List
in thread Comparing Lines within a Word List
Actually, bitwise-xor on strings and tr/// (update: see Quote-Like Operators in perlop) go together quite nicely for something like this:
c:\@Work\Perl\monks>perl -wMstrict -le "use Data::Dump qw(pp); ;; for my $word (qw(Fool Foot Tool Toot Foal)) { my $diff = 'Fool' ^ $word; print qq{'$word': }, pp $diff; print qq{'Fool' and '$word' differ by 1 char} if 1 == $diff =~ tr/\x00//c; } " 'Fool': "\0\0\0\0" 'Foot': "\0\0\0\30" 'Fool' and 'Foot' differ by 1 char 'Tool': "\22\0\0\0" 'Fool' and 'Tool' differ by 1 char 'Toot': "\22\0\0\30" 'Foal': "\0\0\16\0" 'Fool' and 'Foal' differ by 1 char
Update: Changed example code to use tr/\x00//c (/c modifier: complement the search list).
Give a man a fish: <%-{-{-{-<
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Comparing Lines within a Word List
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 | |
Re^3: Comparing Lines within a Word List
by Eily (Monsignor) on Apr 27, 2016 at 18:51 UTC |