in reply to variable compare

Another variation on a theme. All strings assumed to be ASCII strings. All strings do not have to be the same length. Run under Perl version 5.8.9.

c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "my $x = 'YAYBOOAAFUMAAZOT'; my $y = 'YAYFOOAABARA'; ;; my $d = $x ^ $y; dd 'diff string: ', \$d; ;; my @d_seqs; push @d_seqs, [ $-[0], $+[0] - $-[0] ] while $d =~ m{ [^\x00]+ }xmsg; dd 'diff subsequences [offset, len]: ', \@d_seqs; ;; for my $s ($x, $y) { printf qq{'$s' diff subseqs: }; printf qq{'$_' } for map { $_->[0] < length($s) ? substr($s, $_->[0], $_->[1]) : () } +@d_seqs ; print qq{\n}; } " ("diff string: ", \"\0\0\0\4\0\0\0\0\4\24\37\0AZOT") ( "diff subsequences [offset, len]: ", [[3, 1], [8, 3], [12, 4]], ) 'YAYBOOAAFUMAAZOT' diff subseqs: 'B' 'FUM' 'AZOT' 'YAYFOOAABARA' diff subseqs: 'F' 'BAR'
See "Variables related to regular expressions" in perlvar for  @- @+ arrays. (Update: The  $-[0] $+[0] terms in the code above access elements of the  @- @+ arrays respectively.)


Give a man a fish:  <%-{-{-{-<