in reply to Compressing a text file using count of continous characters
Which gives the following output:use strict; sub encode { s/((.)\2+)/(length $1) . $2/eg; $_; } sub decode { $_ = shift; my @list; while (/((\d+)?(.))/g) { push @list, [$2,$3]; } join '', map { (defined $_->[0]) ? $_->[1] x $_->[0] : $_->[1]; } +@list; } while (<DATA>) { print; my $enc = encode($_); my $dec = decode($enc); print $enc; print $dec; } __DATA__ XYZAAAAAAAADEFAAcdAA
XYZAAAAAAAADEFAAcdAA XYZA8DEFA2cdA2 XYZAAAAAAAADEFAAcdAA
---
s;;:<).>|\;\;_>?\\^0<|=!]=,|{\$/.'>|<?.|/"&?=#!>%\$|#/\$%{};;y;,'} -/:-@[-`{-};,'}`-{/" -;;s;;$_;see;
Warning: Any code posted by tuxz0r is untested, unless otherwise stated, and is used at your own risk.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Compressing a text file using count of continous characters
by educated_foo (Vicar) on Dec 14, 2007 at 20:48 UTC |