August 2019 Archives

Splitting on a change in Perl6

I had more thoughts about splitting on character changes, partly thanks to a mailing list thread, which led to more questions.

As a prelude, here are regexps that splits when changing to the letter B

# If the cursor is before B, and is after a character, and is not after B, split

> say "ABBBCDEEF".split(/<?before (B) {} ><?after . ><!after B >/).perl

Splitting on a change, Challenge 20 Task 1

I like reading the Perl Weekly Challenge even if I rarely participate. It struck me that task 1 of Week 20 asked "to accept a string from command line and split it on change of character" - but every solution that I read in the recap looked for runs of the same character instead of the literal interpretation of the challenge.

Then I found, it was a dead end for me...

$ perl -E 'say join " ",split /(.)(?!\1)/,scalar '
 A B B  C  D E E …

About Yary

user-pic Programming for decades, and learning something new every day.