in reply to Splitting a String into n-character parts, without using a regex

I'm confused, are you looking to split the string into arbitrary-length sets of contiguous repeated characters, or just into n-length strings, regardless of whether or not the characters in them repeat? Your choice of strings, 'aabbcccddee', makes this somewhat ambiguous. If you want the former, HAWTDI:
$string='aabbbbbbcccccaaaddeefghhhh'; my @l; push @l, $1.$2 while $string =~ /(\w)(\1*)/g; print join ',', @l; # outputs aa,bbbbbb,ccccc,aaa,dd,ee,f,g,hhhh
Of course, this uses a regex and a while, etc...
  • Comment on Re: Splitting a String into n-character parts, without using a regex
  • Download Code