RosettaCodeData/Task/Run-length-encoding/Perl/run-length-encoding-2.pl

8 lines
139 B
Perl
Raw Permalink Normal View History

2015-11-18 06:14:39 +00:00
sub encode {
shift =~ s/(.)\1{0,254}/pack("C", length($&)).$1/grse;
}
2013-04-10 23:57:08 -07:00
2015-11-18 06:14:39 +00:00
sub decode {
shift =~ s/(.)(.)/$2 x unpack("C", $1)/grse;
2013-04-10 23:57:08 -07:00
}