The OP wanted to compare 10 columns at a time with a sliding window, i.e. columns 1 - 10 then 2 - 11 etc. I think your code will give columns 1 - 10 then 11 - 20 etc.
$ perl -E '
> $rowTxt = ( q{0123456789} x 2 ) . q{0123};
> @groups = $rowTxt =~ m{.{1,10}}g;
> say for @groups;'
0123456789
0123456789
0123
$
Perhaps a look-ahead would give the sliding window the OP wanted.
$ perl -E '
> $rowTxt = ( q{0123456789} x 2 ) . q{0123};
> @groups = $rowTxt =~ m{(?=(.{10}))}g;
> say for @groups;'
0123456789
1234567890
2345678901
3456789012
4567890123
5678901234
6789012345
7890123456
8901234567
9012345678
0123456789
1234567890
2345678901
3456789012
4567890123
$
I'm not sure why the OP is going about the comparison this way. Perhaps s/he wants to pin down exactly where the strings differ. If so, XOR'ing the rows and detecting the position of any ones might be more efficient.
$ perl -E '
> $sa = q{abcdefg};
> $sb = q{abbdegg};
> $df = $sa ^ $sb;
> say q{Zero-based counting};
> 1 while $df =~ m{\x01(?{ say pos( $df ) - 1 })}g;
> say q{One-based counting as per OP example};
> 1 while $df =~ m{\x01(?{ say pos $df })}g;'
Zero-based counting
2
5
One-based counting as per OP example
3
6
$
I hope this is of interest.
|