in reply to Re^4: Efficient 7bit compression
in thread Efficient 7bit compression
my $str =<<'EOS'; There once was a man from Nantucket, Who kept all his cash in a bucket. His daughter, named Nan, Ran off with a man. And as for the bucket, Nantucket. EOS sub shrink_in_place { for (my $i=0; $i<length($_[0]); $i+=7) { for (substr($_[0], $i, 8)) { $_ = pack('B*', grep s/.(.{7})/$1/g, unpack('B*', $_)); } } } sub grow_in_place { for (my $i=0; $i<length($_[0]); $i+=8) { for (substr($_[0], $i, 7)) { $_ = pack('B*', grep s/(.{7})/0$1/g, unpack('B*', $_)); } } } print "$str"; printf "Length is %d\n", length($str); shrink_in_place($str); printf "Shrunk length is %d\n", length($str); grow_in_place($str); print "Restored: $str";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Efficient 7bit compression
by Limbic~Region (Chancellor) on Mar 14, 2005 at 16:43 UTC | |
by Roy Johnson (Monsignor) on Mar 14, 2005 at 18:15 UTC |