Skip to content

Instantly share code, notes, and snippets.

@sshaw
Last active April 5, 2019 12:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sshaw/723b9699b3c7713029311bf97a17e0c0 to your computer and use it in GitHub Desktop.
Save sshaw/723b9699b3c7713029311bf97a17e0c0 to your computer and use it in GitHub Desktop.
Run-length encoding in Perl. Does not support integers :)
perl -E'print $+[1]-$l,$& and $l=$+[1] while $ARGV[0] =~ /(.)(?!\1)/g' aaabbbcdeee
3a3b1c1d3e
perl -E'print $2 x $1 while $ARGV[0] =~ /(\d+)(.)/g' 3a3b1c1d3e
aaabbbcdeee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment