in reply to group things?
Maybe you can modify this function to capture the beginning and ending positions of each run.sub encode { (my $string = shift) =~s/((.)\2*)/$2 . (length $1) /eg; $string; }
Update: Spoiler follows...
sub group { my $x = shift; my $pos = 0; my @groups; $x =~ s{ ((.)\2*) (?{ push(@groups, [ substr($^N,0,1), $pos, $pos+length($^N) + ]); $pos+=length($^N) }) }{}gx; \@groups; }
|
|---|