Created
July 19, 2016 23:52
-
-
Save pjf/473bdd1875cda874e4a8c66c8ae07108 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
use 5.010; | |
use strict; | |
use warnings; | |
use autodie; | |
while (<>) { | |
# This requires at least two characters to fire, because we're searching | |
# for a character, followed by repeats ('+') of that character. | |
# | |
# We're doing string substitution (rather than building a new string), | |
# so if something doesn't match, we just leave it alone. | |
s{ | |
(?<string> # The whole string of repeated characters. | |
(?<char>.) # The first character | |
\g{char}+ # The same character, as many times we can. | |
) | |
}{$+{char} . length($+{string} ) }exg; # Replace with character and length of string. | |
print; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment